0

我正在为我的授权服务器和受保护的 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一个调用,我如何告诉 fetch 客户端使用非默认端点?

4

1 回答 1

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;
    });
 }

}

于 2017-07-03T11:04:49.357 回答