Skip to content
This repository has been archived by the owner on Jun 4, 2023. It is now read-only.

Commit

Permalink
express: force SSL
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfolsche authored and vincentbernat committed Jul 7, 2015
1 parent 6dcc214 commit 499b79f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ nconf
// Other stuff
port: 9400,
demo: false,
secret: 'changeThisLameSecretPassphrase!!'
secret: 'changeThisLameSecretPassphrase!!',
forcessl: false
}
});

Expand Down
12 changes: 12 additions & 0 deletions lib/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ if (app.get('env') === 'development') {
}));
}



if (config.get('forcessl')) {
var forceSsl = function(req, res, next) {
if (req.headers['x-forwarded-proto'] !== 'https') {
return res.redirect(['https://', req.get('Host'), req.url].join(''));
}
return next();
};
app.use(forceSsl);
}

app.use(express.static(config.get('path:static')));
app.use(methodOverride());
logger.express.access(app);
Expand Down

0 comments on commit 499b79f

Please sign in to comment.