javascript - 如何在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);
});
}
解决方案
推荐阅读
- php - 在节点 js 上使用 phantom html 到 pdf 时,pdf 文件对齐不好
- python - 压缩 pkl 文件
- android - 如何更改未聚焦的textInputLayout的轮廓或边框的颜色?
- c# - C# WPF DataGrid 事件处理程序,用于读入列中可编辑的 ComboBox 值
- python - 使用硒的谷歌帐户登录自动化导致错误
- javascript - 如何通过意图将图像从网页共享到whatapp
- geometry - 使用这个类创建一个圈子
- caching - 如何在不为特定文件夹和文件提供在线访问的情况下使用 IPFS?
- spring - Spring Data Jpa Oracle 无法创建表
- javascript - 从 JS 获取变量