Skip to content

Commit

Permalink
fix datasets#107: add https redirection in production mode
Browse files Browse the repository at this point in the history
  • Loading branch information
augusto-herrmann committed Sep 20, 2021
1 parent 9adc9bc commit 7c9b7b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ app.use(express.static(path.join(__dirname, 'public')));
if ('development' === process.env.NODE_ENV) {
app.use(errorhandler());
}
else { // production only
// handle https redirect
function ensureSecure(req, res, next){
if(req.secure){
// OK, continue
return next();
};
res.redirect('https://' + req.hostname + req.url);
}
app.all('*', ensureSecure);
}

app.get('/', routes.index);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "publicbodies",
"version": "0.1.0",
"version": "0.1.1",
"description": "A database of public bodies such as government departments, ministries etc.",
"main": "site/make.js",
"directories": {
Expand Down

0 comments on commit 7c9b7b9

Please sign in to comment.