Created
March 18, 2017 16:19
-
-
Save rla/ce46909f4aa1cf742f63496c1884c0c1 to your computer and use it in GitHub Desktop.
Middleware to redirect to HTTPS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Middleware to redirect to HTTPS. | |
module.exports = () => { | |
return (req, res, next) => { | |
if (req.protocol !== 'https') { | |
const host = req.hostname; | |
if (host && !req.url.match(/\.well-known/)) { | |
res.redirect(301, `https://${host}${req.url}`); | |
} else { | |
next(); | |
} | |
} else { | |
next(); | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment