angular - 在应用程序中使用 config.json 文件的参数
问题描述
我们正在使用谷歌地图 api,我们有一个密钥。我们已将此密钥编码在我们的模块文件之一中。我们想在 config.json 文件中使用这个密钥,这样它应该是安全的,当我们将更改推送到 git 时,它不应该是可用的,因为我们不会在 git 上推送我们的 config.json 文件。我对此一无所知。
移动内容.module.ts
@NgModule({
imports: [
AgmCoreModule.forRoot({
apiKey: 'GOOGLE-API KEY',
libraries: ['places']
}),
hip-config.json
googleMapsApiKey: "GOOGLE-API KEY" <--- want to use here ONLY
我只想在 hip-config.json 文件中使用此键,并希望将其从 mobile-content.module.ts 文件中删除。
有没有办法暗示这样的事情?
解决方案
导入hip-config.json
你的模块文件
import config from "../config/hip-config.json";
替换模块中的硬编码密钥
```
@NgModule({
imports: [
AgmCoreModule.forRoot({
apiKey: 'config.GOOGLE-API KEY',
libraries: ['places']
}),
```
确保hip-config.json
已将其添加到,.gitignore
以免意外被推送。
推荐阅读
- javascript - 如何使用 HTML5 和 Javascript 读取 Firebase 数据?
- javascript - 如何在 JavaScript 中更改多维数组的值?
- node.js - Firebase Cloud Functions encrypt and decrypt using SHA256 RSA crashing
- amazon-web-services - CloudFormation Rollback on Template? When changing default region in template
- php - 我想比较表格 SYMFONY4 上的两个属性
- java - 如何阻止 maven-release-plugin 使用旧版本的 maven-gpg-plugin
- python - Nested List declaration
- r - Read multiple tables from csv with fread and deal with blank files
- r - readline inserts a line break before the prompt in the R console
- apache-flink - 如何从 flink 中的本地套接字消费,端口号后面有“/*”,其中 * 是源的其余部分?