My middleware
exports.redirectToHTTPS = (req, res, next) => {
if (req.protocol == "https") {
return next()
}
const redirect_not = req.query.redirect
console.log("!!!!! Connection not secure")
const redirect_url = ['https://', req.get('host'), req.originalUrl].join('')
console.log("REDIRECT_URL:- " + redirect_url)
return res.redirect(redirect_url)
}
in index.js
app.use(redirectToHTTPS)
I am using express.js and node.js