【问题标题】:How do I configure FetchClient to use a non-default api when using Aurelia Auth使用 Aurelia Auth 时如何配置 FetchClient 以使用非默认 api
【发布时间】:2017-07-03 19:04:49
【问题描述】:

我正在为我的授权服务器和受保护的 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 客户端使用非默认端点?

【问题讨论】:

    标签: aurelia aurelia-auth


    【解决方案1】:

    我走错了路,你使用 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;
        });
     }
    

    }

    【讨论】:

      猜你喜欢
      • 2018-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多