2017-11-09 10 views
0

私は、main.jsに登録されているaurelia-apiの2つのエンドポイントを持っています。 1つは私のステージングサーバー、もう1つはローカル開発サーバー(Kestrel)を指しています。Aurelia-APIにおけるエンドポイントの環境ベースの切り替え

推奨レジスタのエンドポイントへの道か、私は簡単に環境に基づいてそれらを切り替えることができるように、デフォルトのエンドポイントを設定するとは何ですか?

.plugin('aurelia-api', config => { 
    config 
    //.registerEndpoint('api', 'http://localhost:5000/api/')  
    .registerEndpoint('api', 'http://server:port/api/') 

    .setDefaultEndpoint('api'); 
}) 

答えて

1

ご使用の環境に基づいて何かを設定する最良の方法は、あなたがdevprod環境を含む、あなたのアプリを起動したときオーレリアが作成する、environmentsフォルダを利用しています。

dev.ts:

export default { 
    debug: true, 
    testing: true, 
    endpoint: "http://localhost:5000/api" 
} 

prod.ts

export default { 
    debug: false, 
    testing: false, 
    endpoint: "http://server:port/api/" 
} 

これら

を使用すると、ローカルまたはサーバー上でそれを実行しているかどうかに基づいて、ファイル environment.tsにコンパイルします。

、あなたのファイルに環境を注入した場合、あなたはそのように、それに指定された任意の変数を使用することができます: `environment`ファイルに関する

import environment from "./environment"; 

export function configure(aurelia) { 
aurelia.use 
    .plugin('aurelia-api', config => { 
    config 
    .registerEndpoint('api', environment.endpoint) 

    .setDefaultEndpoint('api'); 
}) 
+0

詳細情報:https://stackoverflow.com/質問/ 2972​​2814 /環境設定のためのハウリングセット –

関連する問題