When I used node.js as a proxy server in the past, the way we got unprotected connections to the proxy server for protection was as follows, modified according to your code:
const httpsPort = process.env.HTTPS_PORT;
app.use(function(req, res, next) {
if (req.secure) {
return next();
}
res.redirect(301, ['https://', req.hostname, ':', httpsPort, '/', req.url].join('');
}
Where httpsPort- whatever your port, your standard https connections. Where process.env.HTTPS_PORTwill get the environment variable for the https port (standard - 443). You can replace this with anything you want to get a port.
source
share