2017-06-29 45 views
0

我設立Aurelia路上,權威性和我的授權服務器配置的端點和受保護的API時:如何配置FetchClient使用非默認的API使用奧裏利亞驗證

aurelia.use.plugin('aurelia-api', configure => { 
configure 
    .registerEndpoint('auth', 'http://localhost:5000/') 
    .registerEndpoint('api', 'http://localhost:5006')} 

當我想獲取數據我注入AuthService到我的模塊,然後調用

this.authService.config.client.client.fetch('StaticData/offices') 

但這要求對auth端點不是api一個,我怎麼告訴抓取客戶端使用非默認的終點?

回答

0

我正在走向歧途,需要使用配置對象關aurelia-api得到一個端點,你可以調用:

import { inject } from 'aurelia-framework'; 
import { Config } from 'aurelia-api' 


@inject (Config) 
export class Locations { 
    constructor (private apiEndpointConfig: Config) 
    {} 
    dataItems; 
    hasItems: boolean; 

    created(){ 

    var api = this.apiEndpointConfig.getEndpoint('api'); 
    api.client.fetch('StaticData/offices') 
    .then(response=>response.json()) 
    .then(response=> 
    { 
     this.dataItems=response; 
     this.hasItems=true; 
    }); 
} 

}