简体   繁体   English

回送中的动态datasource.json

[英]Dynamic datasource.json in loopback

I am using loopback with nodejs. 我正在使用nodejs的环回。

In my datasource.json file i have a connection Settings 在我的datasource.json文件中,我有一个连接设置

"mongoConnector": {
    "host": "127.0.0.1",
    "port": 27017,
    "url": "",
    "database": "DB",
    "password": "",
    "name": "mongoConnector",
    "user": "",
    "connector": "mongodb"
  }

I have a global config json file which contains db connection settings like pwd, host ... 我有一个全局配置json文件,其中包含db连接设置,例如pwd,host ...

Is there any way to modify mongoConnector dynamically according to global config file. 有什么方法可以根据全局配置文件动态修改mongoConnector。

You'll have to use a .js configuration file for this. 为此,您必须使用.js配置文件。 You can create either a server/datasources.local.js (will always take precedence over other config files). 您可以创建server/datasources.local.js (始终优先于其他配置文件)。 Or you can use a NODE_ENV environment variable to specify a different suffix (ie datasources.{NODE_ENV}.js ). 或者,您可以使用NODE_ENV环境变量来指定其他后缀(即datasources.{NODE_ENV}.js )。 In the file, just export an object that contains your configuration. 在文件中,只需导出包含您的配置的对象。 You can use process.env.FOO to get environment variables. 您可以使用process.env.FOO来获取环境变量。 You could also require() your global file inside the .js config file, and pull from there. 您还可以在.js配置文件中require()您的全局文件,然后从那里拉出。 It's up to you. 由你决定。

You can find some more info on the LB docs . 您可以在LB文档上找到更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM