Stop header errors on www

This commit is contained in:
Jonathan Cremin 2014-12-07 18:47:05 +00:00
parent 7468cc4ea6
commit 2241e16e5f

4
app.js
View file

@ -52,7 +52,7 @@ app.use(function(req, res, next) {
app.get('*', function(req,res,next) {
// force SSL
if (req.headers['cf-visitor'] && req.headers['cf-visitor'] != '{"scheme":"https"}') {
res.redirect("https://" + req.headers['host'] + req.url);
return res.redirect("https://" + req.headers['host'] + req.url);
} else if (req.headers['cf-visitor']) {
req.userProtocol = "https";
} else {
@ -60,7 +60,7 @@ app.get('*', function(req,res,next) {
}
// redirect www
if (req.headers.host.match(/^www/) !== null ) {
res.redirect(req.userProtocol + '://' + req.headers.host.replace(/^www\./, '') + req.url);
return res.redirect(req.userProtocol + '://' + req.headers.host.replace(/^www\./, '') + req.url);
} else {
next();
}