Permalink
Browse files

defaulting to production mode (#711)

cleaning up failed exec handling

fixing stop error
  • Loading branch information...
1 parent 16d2615 commit 57a7225f5091641b8c0992eb8993ffc40cdb67b1 @jmervine jmervine committed on GitHub Aug 3, 2016
Showing with 56 additions and 32 deletions.
  1. +10 −2 app.js
  2. +9 −4 app.json
  3. +2 −2 docker-compose.yml
  4. +34 −23 make.js
  5. +1 −1 package.json
View
@@ -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 }));
View
@@ -1,6 +1,11 @@
{
- "name":"bootstrap-cdn",
- "scripts":{},
- "env":{},
- "addons":[]
+ "name": "bootstrap-cdn",
+ "scripts": {},
+ "env": {
+ "FORCE_SSL": {
+ "description": "Force SSL redirection",
+ "value": "true"
+ }
+ },
+ "addons": []
}
View
@@ -5,6 +5,6 @@ web:
- .:/app/user
command: npm run run
environment:
- - PORT=3000
+ - PORT=3333
ports:
- - "3000:3000"
+ - "3333:3333"
View
@@ -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
@@ -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();
};
//
@@ -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);
View
@@ -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"
},

0 comments on commit 57a7225

Please sign in to comment.