在 app 中使用 config.json 文件的参数 [英] Use config.json file's parameters in app

查看:26
本文介绍了在 app 中使用 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 hip-config.json into your module file

从../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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆