在应用程序中使用 config.json 文件的参数
Use config.json file's parameters in app
我们正在使用 google 地图 api 并且我们有一把钥匙。我们已经在我们的模块文件之一中对这个密钥进行了编码。我们想在 config.json 文件中使用此密钥,这样它应该是安全的,并且当我们将更改推送到 git 时,它不应该可用,因为我们没有将我们的 config.json 文件推送到 git。我对此一无所知。
手机-content.module.ts
@NgModule({
imports: [
AgmCoreModule.forRoot({
apiKey: 'GOOGLE-API KEY',
libraries: ['places']
}),
臀围-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
,以免意外被推送。
我们正在使用 google 地图 api 并且我们有一把钥匙。我们已经在我们的模块文件之一中对这个密钥进行了编码。我们想在 config.json 文件中使用此密钥,这样它应该是安全的,并且当我们将更改推送到 git 时,它不应该可用,因为我们没有将我们的 config.json 文件推送到 git。我对此一无所知。
手机-content.module.ts
@NgModule({
imports: [
AgmCoreModule.forRoot({
apiKey: 'GOOGLE-API KEY',
libraries: ['places']
}),
臀围-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
,以免意外被推送。