diff --git a/lib/compiler.js b/lib/compiler.js index ef9aecc..b28bb20 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -95,6 +95,7 @@ module.exports = function compile(options) { // loopback modifies the data. Since we are loading the data using `require`, // such change affects also code that calls `require` for the same file. var instructions = { + env: env, config: appConfig, dataSources: dataSourcesConfig, models: modelInstructions, diff --git a/lib/executor.js b/lib/executor.js index c44ca75..844c237 100644 --- a/lib/executor.js +++ b/lib/executor.js @@ -23,6 +23,7 @@ module.exports = function execute(app, instructions, callback) { patchAppLoopback(app); assertLoopBackVersion(app); + setEnv(app, instructions); setHost(app, instructions); setPort(app, instructions); setApiRoot(app, instructions); @@ -87,6 +88,12 @@ function assertLoopBackVersion(app) { } } +function setEnv(app, instructions) { + var env = instructions.env; + if (env !== undefined) + app.set('env', env); +} + function setHost(app, instructions) { // jscs:disable requireCamelCaseOrUpperCaseIdentifiers var host = diff --git a/test/executor.test.js b/test/executor.test.js index 42d2ff6..52564af 100644 --- a/test/executor.test.js +++ b/test/executor.test.js @@ -362,6 +362,11 @@ describe('executor', function() { })); } + it('should apply env passed in option object', function() { + boot.execute(app, someInstructions({ env: 'custom_env' })); + expect(app.get('env')).to.equal('custom_env'); + }); + it('should honor host and port', function() { function assertHonored(portKey, hostKey) { process.env[hostKey] = randomPort(); @@ -854,6 +859,9 @@ function someInstructions(values) { } }; + if (values.env) + result.env = values.env; + if (values.files) { for (var k in values.files) result.files[k] = values.files[k];