首页 > 解决方案 > 如何在Angular2中发布配置

问题描述

我有一个 Angular2 应用程序,其配置文件位于服务器(/assets/data/config.json)上。该文件包含后端不同服务的 url,例如 Loggingservice、Appservice 和 Identityservice。加载文件不是问题,但如果我想更新文件,服务器会以 404 响应...

是否可以在没有额外服务的情况下将新配置放到服务器上,只需使用 Node.js 服务器?请求的授权标头必须根据硬编码哈希在服务器端进行验证

我的更新功能如下所示:

public setConfig(config: IAppConfig, authHash: string): void {
  const httpOptions = {
    headers: new HttpHeaders({
      'Content-Type': 'application/json',
      'Authorization': authHash
    })
  };

  this.http.put<IAppConfig>(this.configPath, config, httpOptions)
    .toPromise()
    .then(() => {
      this.logger.log(this, 'configuration successfully updated!');
    }, (error: HttpErrorResponse) => {
      this.logger.error(this, 'configuration could not be updated!' + error.error);          
  });
}

标签: javascriptnode.jsangularhttpauthentication

解决方案


推荐阅读