Adding option for http to redirect to https
This commit is contained in:
parent
5e6358602e
commit
95050849d8
|
@ -2,6 +2,7 @@
|
||||||
"http": true,
|
"http": true,
|
||||||
"http_host": "0.0.0.0",
|
"http_host": "0.0.0.0",
|
||||||
"http_port": 7777,
|
"http_port": 7777,
|
||||||
|
"http_redirect_to_https": false,
|
||||||
|
|
||||||
"https": false,
|
"https": false,
|
||||||
"https_host": "0.0.0.0",
|
"https_host": "0.0.0.0",
|
||||||
|
|
15
server.js
15
server.js
|
@ -186,15 +186,20 @@ app.use(connect_st({
|
||||||
index: 'index.html'
|
index: 'index.html'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
if (config.http) {
|
if (config.http) {
|
||||||
http.createServer(app).listen(config.http_port, config.http_host);
|
if (config.http && config.https && config.http_redirect_to_https){
|
||||||
winston.info('listening on http:\/\/' + config.http_host + ':' + config.http_port);
|
http.createServer(function(req, res) {
|
||||||
|
res.writeHead(301, { "Location": "https:\/\/" + req.headers['host'] + req.url });
|
||||||
|
res.end();
|
||||||
|
}).listen(config.http_port, config.http_host)
|
||||||
|
winston.info('redirecting http traffic to https');
|
||||||
|
} else {
|
||||||
|
http.createServer(app).listen(config.http_port, config.http_host);
|
||||||
|
winston.info('listening on http:\/\/' + config.http_host + ':' + config.http_port);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.https) {
|
if (config.https) {
|
||||||
https.createServer(https_options, app).listen(config.https_port, config.https_host);
|
https.createServer(https_options, app).listen(config.https_port, config.https_host);
|
||||||
winston.info('listening on https:\/\/' + config.https_host + ':' + config.https_port);
|
winston.info('listening on https:\/\/' + config.https_host + ':' + config.https_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue