Fehler bei undefinertem hHost abgefangen

This commit is contained in:
Robert Richter 2019-05-11 22:29:08 +02:00
parent 751d0cdb70
commit dc76e5c7b6

View File

@ -43,11 +43,19 @@ webserver.listen(app_cfg.global.https_port, function() {
// Redirect all HTTP traffic to HTTPS // Redirect all HTTP traffic to HTTPS
http.createServer(function(req, res) { http.createServer(function(req, res) {
var host = req.headers.host; var host = req.headers.host;
// prüfen ob host gesetzt, sonst 404
if (typeof host !== 'undefined' && host) {
// Anfrage auf https umleiten
host = host.replace(/:\d+$/, ":" + app_cfg.global.https_port); host = host.replace(/:\d+$/, ":" + app_cfg.global.https_port);
res.writeHead(301, { res.writeHead(301, {
"Location": "https://" + host + req.url "Location": "https://" + host + req.url
}); });
res.end(); res.end();
} else {
// HTTP status 404: NotFound
res.status(404)
.send('Not found - use https instead!');
};
}).listen(app_cfg.global.http_port); }).listen(app_cfg.global.http_port);
// TODO: auf HTTPS mit TLS1.2 umstellen, inkl. WSS // TODO: auf HTTPS mit TLS1.2 umstellen, inkl. WSS