Set app env if it is supplied in options object

Set the app env if it is supplied in options object which solves issue
number 28 under loopback-boot repo
This commit is contained in:
Amir Jafarian 2015-11-25 16:26:09 -05:00
parent 088ca864c2
commit 2574c9dbb6
3 changed files with 16 additions and 0 deletions

View File

@ -95,6 +95,7 @@ module.exports = function compile(options) {
// loopback modifies the data. Since we are loading the data using `require`, // loopback modifies the data. Since we are loading the data using `require`,
// such change affects also code that calls `require` for the same file. // such change affects also code that calls `require` for the same file.
var instructions = { var instructions = {
env: env,
config: appConfig, config: appConfig,
dataSources: dataSourcesConfig, dataSources: dataSourcesConfig,
models: modelInstructions, models: modelInstructions,

View File

@ -23,6 +23,7 @@ module.exports = function execute(app, instructions, callback) {
patchAppLoopback(app); patchAppLoopback(app);
assertLoopBackVersion(app); assertLoopBackVersion(app);
setEnv(app, instructions);
setHost(app, instructions); setHost(app, instructions);
setPort(app, instructions); setPort(app, instructions);
setApiRoot(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) { function setHost(app, instructions) {
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers // jscs:disable requireCamelCaseOrUpperCaseIdentifiers
var host = var host =

View File

@ -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() { it('should honor host and port', function() {
function assertHonored(portKey, hostKey) { function assertHonored(portKey, hostKey) {
process.env[hostKey] = randomPort(); process.env[hostKey] = randomPort();
@ -854,6 +859,9 @@ function someInstructions(values) {
} }
}; };
if (values.env)
result.env = values.env;
if (values.files) { if (values.files) {
for (var k in values.files) for (var k in values.files)
result.files[k] = values.files[k]; result.files[k] = values.files[k];