diff --git a/app.js b/app.js index 14c6ce9..a3e9826 100644 --- a/app.js +++ b/app.js @@ -48,8 +48,9 @@ app.use(function(req, res, next) { next(); }) -// force SSL + 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); } else if (req.headers['cf-visitor']) { @@ -57,7 +58,12 @@ app.get('*', function(req,res,next) { } else { req.userProtocol = "http" } - next(); + // redirect www + if (req.headers.host.match(/^www/) !== null ) { + res.redirect(req.userProtocol + '://' + req.headers.host.replace(/^www\./, '') + req.url); + } else { + next(); + } }); app.get('/', function(req, res) {