I have an angular 5 app which is hosted on heroku. Currently the users can access the HTTP version of the app.
How can I force the users to be redirected to HTTPS version even if they access HTTP?
What I have tried:
app.use(function (req, res, next) {
let sslUrl;
if (process.env.NODE_ENV === 'production' &&
req.headers['x-forwarded-proto'] !== 'https') {
sslUrl = ['https://myapp.herokuapp.com', req.url].join('');
return res.redirect(sslUrl);
}
return next();
});
I have placed the above code in my node.js server but it has not worked.
The users are unable to use the app over HTTP as they get a 403 ERROR