Skip to content

Commit

Permalink
defaulting to production mode (#711)
Browse files Browse the repository at this point in the history
cleaning up failed exec handling

fixing stop error
  • Loading branch information
jmervine committed Aug 3, 2016
1 parent 16d2615 commit 57a7225
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 32 deletions.
12 changes: 10 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@ app.set('view engine', 'pug');

app.disable('x-powered-by');

// production
if (env === 'production') {
// production
app.use(logger('combined'));
app.use(enforce.HTTPS({ trustProtoHeader: true }));

if (process.env.FORCE_SSL === 'true') {
// Because this is (always) going to break local, I'm requiring a secondary
// environment variable to be enabled to activate it. This is required in
// app.json to ensure that it's always set when building out the app on
// Heroku.
app.use(enforce.HTTPS({ trustProtoHeader: true }));
}
} else {
// development
app.locals.pretty = true;
app.use(logger('dev'));
app.use(errorHandler({ dumpExceptions: true, showStack: true }));
Expand Down
13 changes: 9 additions & 4 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"name":"bootstrap-cdn",
"scripts":{},
"env":{},
"addons":[]
"name": "bootstrap-cdn",
"scripts": {},
"env": {
"FORCE_SSL": {
"description": "Force SSL redirection",
"value": "true"
}
},
"addons": []
}
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ web:
- .:/app/user
command: npm run run
environment:
- PORT=3000
- PORT=3333
ports:
- "3000:3000"
- "3333:3333"
57 changes: 34 additions & 23 deletions make.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ var MOCHA_OPTS = ' --timeout 15000 --slow 500';
(function() {
cd(__dirname);

function assert(result) {
if (result.code !== 0) {
process.exit(result.code);
var ignoreFailure = function() {};
var handleFailure = function(code) {
process.exit(code);
};

// map default execute with desired error handling
var assertExec = function(cmd, options) {
if (options) {
exec(cmd, options, handleFailure);
}
}
function assertExec(cmd) {
assert(exec(cmd));
}

exec(cmd, handleFailure);
};

//
// make test
Expand Down Expand Up @@ -54,15 +59,28 @@ var MOCHA_OPTS = ' --timeout 15000 --slow 500';
};

// for functional tests
target.start = function() {
assertExec(FOREVER + ' --plain start app.js');
target.start = function(callback) {
var env = process.env;

if (!env.NODE_ENV) {
env.NODE_ENV = 'production';
}

exec(FOREVER + ' start --plain app.js', { env: env });
};

target.stop = function() {
assertExec(FOREVER + ' stop app.js');
};

target.tryStop = function() {
// use remapped default exec behavior from shelljs to ignore failures
exec(FOREVER + ' stop app.js', ignoreFailure);
};

target.restart = function() {
assertExec(FOREVER + ' stop app.js');
assertExec(FOREVER + ' --plain start app.js');
target.tryStop();
target.start();
};

//
Expand Down Expand Up @@ -123,27 +141,20 @@ var MOCHA_OPTS = ' --timeout 15000 --slow 500';

response.on('end', function() {
file.close();

outputs.push(output);

callback();
});
});
}, function(err) {
echo('+ node make stop');
try {
// it's okay if this fails
target.stop();
} catch (e) { }
}, function() {
echo('+ node make tryStop');
target.tryStop();

echo('+ bootlint ' + outputs.join('\\\n\t'));

// disabling version error's until bootswatch is updated to 3.3.4
exec(BOOTLINT + ' -d W013 ' + outputs.join(' '), function(code, stdout) {
exec(BOOTLINT + ' -d W013 ' + outputs.join(' '), function(code) {
rm(outputs);
if (code !== 0) {
process.exit(code);
}
handleFailure(code);
});
});
}, 2000);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"request": "^2.64.0",
"serve-favicon": "^2.3.0",
"serve-static": "^1.10.0",
"shelljs": "^0.5.3",
"shelljs": "^0.7.2",
"snyk": "^1.17.1",
"sri-toolbox": "^0.2.0"
},
Expand Down

0 comments on commit 57a7225

Please sign in to comment.