Skip to content

Commit

Permalink
Add: forceHttps (Closes #24)
Browse files Browse the repository at this point in the history
  • Loading branch information
psi-4ward committed Dec 14, 2018
1 parent a2e4f0c commit 39a4828
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const config = {
"sslPort": 8443,
"sslKeyFile": false,
"sslCertFile": false,
// Force redirect to https
// can be true or a specific url like https://example.com:8443
// keep empty to disable
"forceHttps": '',
// retention options in seconds:label
"retentions": {
"one-time": "one time download",
Expand Down
9 changes: 9 additions & 0 deletions lib/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ if (config.accessLog) {
app.use(morgan(config.accessLog));
}

if(config.forceHttps) {
app.enable('trust proxy');
app.use(function(req, res, next) {
if (req.secure) return next();
const target = config.forceHttps === 'true' ? 'https://' + req.headers.host : config.forceHttps;
res.redirect(target + req.url);
});
}

// Static files
app.use('/app', express.static(path.join(__dirname, '../public/app')));
app.use('/assets', express.static(path.join(__dirname, '../public/assets')));
Expand Down

0 comments on commit 39a4828

Please sign in to comment.