Environment-specific configuration server/config.{env}.json cannot load properly
@bajtos @crandmck
I have 6 config files
server/config.json server/config.test.json server/config.production.json
server/config.local.js server/config.test.js server/config.production.js
config.{env}.js is used for errorHandler
NODE_ENV="test" node . NODE_ENV=test node .
It does not load the right config.
Another question is, can I use config.js for errorHandling rather then config.local.js shown in the doc.
server/datasources.{env}.json/js work and load the right file tho.
It does not load the right config.
Please provide more details.
Ideally, create a sample application we can use to reproduce your problem, per our wiki instructions.
Possibly related: https://github.com/strongloop/loopback-boot/pull/71
I've seen this happen due to a configuration issue, it's been discussed reguarding the explorer component in component-config.json. config.json is loaded first, then properties are merged in from the other env specific file. So be careful what you're trying to change, you can't replace an object with a boolean for example (like the explorer issue)
@bajtos @noderat
Let say I have 2 config
config.json
{
"restApiRoot": "/api",
"host": "0.0.0.0",
"port": 80,
"blur": false
}
config.test.json
{
"restApiRoot": "/api",
"host": "0.0.0.0",
"port": 80,
"test": true
}
If I start the server, NODE_ENV="test" node . app.get('test') should be true. app.get('blur') should be undefined
On the other hand, if the server is run, node . app.get('test') should be undefined
Either way, only config.json is loaded
Is it possible to create additional properties inside a config.{env}.json/js file ? I'm not so sure
@Overdrivr Yes additional properties can be added as shown in @mike-aungsan's example
@noderat Yes, they can be added, but are you definitively sure they are taken into account ? Is it not mandatory to override a property that already exist in the default configuration ?
I have seen a stack overflow question where a database was defined only in alternate config, and that caused issues and was not taken into account in alternative config. I can try to find the post back if you want.
I am currently adding additional properties in every single configuration .json within server for *.local.json, *.staging.json and *.production.json without any problems.
The biggest problem people run in to is trying to replace an object with a boolean or something similar. Because of this I heavily use the "enabled" booleans available in each configuration file rather than just setting an entire property to false.
@noderat Thank you for clarifying that.
looks like the issue has been resolve, closing issue now, please ping me here or open a new issue if as you see fit.
@davidcheung I have the scenario for the issue Let say I have 2 config
config.json
{
"restApiRoot": "/api",
"host": "0.0.0.0",
"port": 80,
"blur": "disabled"
}
and config.test.json
{
"restApiRoot": "/api",
"host": "0.0.0.0",
"port": 80,
"blur": "allow"
}
and In the other hand, you added the example code for versioning your API.
var p = require('../package.json');
var version = p.version.split('.').shift();
module.exports = {
restApiRoot: '/api' + (version > 0 ? '/v' + version : ''),
host: process.env.HOST || 'localhost',
port: process.env.PORT || 3000
};
when you try to get the value of blur property with
app.get('blue')
you get the value from the config.json, not from config.test.json. The issue occurs only when a javascript configuration file exists
@rikantro thank you for chiming in. Could you please open a new issue and include a runnable application demonstrating the problem? See http://loopback.io/doc/en/contrib/Reporting-issues.html#bug-report