2017-06-29 42 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; 
    }); 
} 

}