Created
February 1, 2019 10:22
-
-
Save olegpolyakov/ef842858538b5cdf40db21a352252a0d to your computer and use it in GitHub Desktop.
Express middleware to ensure HTTPS
This file contains hidden or 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
function https(req, res, next) { | |
if (req.secure) | |
next(); | |
else if (req.method === 'GET') | |
res.redirect(301, `https://${req.headers.host}${req.originalUrl}`); | |
else | |
res.status(403).send('Для доступа к сайту необходимо использовать защищенное соединение через HTTPS.'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment