如何在使用Aurelia Auth时将FetchClient配置为使用非默认api

时间:2017-06-29 15:45:13

标签: aurelia aurelia-auth

我正在为我的授权服务器和受保护的api设置aurelia-auth并配置端点:

  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端点,如何告诉获取客户端使用非默认端点?

1 个答案:

答案 0 :(得分: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;
    });
 }

}