【发布时间】:2019-10-18 22:17:20
【问题描述】:
我已经实现了从我的 Angular 应用程序的 JSON 文件中读取的应用程序配置,以便在部署后轻松配置它。 我们使用 Octopus 部署工具来部署 Angular 应用程序。如您所知,他的 enviornment.ts 文件将生成为 js 文件,并且 通过读取 JS 文件来操作 Octopus 中的设置非常困难。因此,我创建了 config.JSON 文件,该文件将输出到 dist 文件夹和 Octopus deploy 可以使用 JSON 文件在需要时进行更改。
当前应用程序正在从环境 ts 文件中读取值,而后者又在读取 Config.JSON 文件中设置的值。
我想知道我的方法是否正确?
配置.JSON
{
"settings": {
"production": false,
"userIdleMinutes": "10",
"corePingIntervalSeconds": "10",
"baseUrl": "http://localhost:57973",
"loginUrl": "/Login",
"adminUrl": "/Admin"
}
}
环境.ts
import config from '../assets/config.json'
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.
export const environment = {
production: config.settings.production,
baseUrl: config.settings.baseUrl,
loginUrl:config.settings.loginUrl,
adminUrl: config.settings.adminUrl,
userIdleMinutes: config.settings.userIdleMinutes,
corePingIntervalSeconds: config.settings.corePingIntervalSeconds
};
【问题讨论】:
-
我不明白你的方法为什么不正确。 a) 有效; b) 它允许从 Octopus 注入依赖于环境的值。
标签: json angular octopus-deploy