Merge pull request #164 from strongloop/set-app-env

Set app env if it is supplied in options object
This commit is contained in:
Miroslav Bajtoš 2015-12-02 16:38:54 +01:00
commit 4e3e1a7394
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`,
// such change affects also code that calls `require` for the same file.
var instructions = {
env: env,
config: appConfig,
dataSources: dataSourcesConfig,
models: modelInstructions,

View File

@ -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 =

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() {
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];