Use config.json file's parameters in app

倾然丶 夕夏残阳落幕 提交于 2019-12-11 16:31:28

问题


We are using google map api and we have a key. We have codede this key in one of our module file. We want to use this key in config.json file so that it should be secure and when we push our changes to git, it should not be available as we dont push our config.json file on git. I don't have any idea about this.

mobile-content.module.ts

@NgModule({
  imports: [
    AgmCoreModule.forRoot({
      apiKey: 'GOOGLE-API KEY',
      libraries: ['places']
    }),

hip-config.json

googleMapsApiKey: "GOOGLE-API KEY" <--- want to use here ONLY

I want to use this key in hip-config.json file only and want to remove it from mobile-content.module.ts file.

Is there any way to impliment such thing?


回答1:


Import hip-config.json into your module file

import config from "../config/hip-config.json";

Replace the hard-coded key in the module

```

@NgModule({
  imports: [
    AgmCoreModule.forRoot({
      apiKey: 'config.GOOGLE-API KEY',
      libraries: ['places']
    }),

```

Make sure that hip-config.json has been added to .gitignore so it doesn't accidentally get pushed.



来源:https://stackoverflow.com/questions/50798523/use-config-json-files-parameters-in-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!