本文介绍了在应用程序中使用config.json文件的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用google map api,我们有一个密钥.我们已将此密钥编码在我们的模块文件之一中.我们想在config.json文件中使用此密钥,以便它应该是安全的,并且当我们将更改推送到git时,由于我们不将config.json文件推送到git上,因此它不可用.我对此一无所知.

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

mobile-content.module.ts

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

hip-config.json

hip-config.json

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

我只想在hip-config.json文件中使用此密钥,并希望将其从mobile-content.module.ts文件中删除.

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?

推荐答案

hip-config.json导入模块文件

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']
    }),

```

请确保已将hip-config.json添加到.gitignore,以免意外将其推入.

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

这篇关于在应用程序中使用config.json文件的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 20:25