It should be done in your application. Please check this post https://stackoverflow.com/a/54289378/5293578
I've tried the following code and it worked for me (You must put this before the default request and error handler):
/**==== File: server.js =======**/
/** Express configuration **/
// HTTPS Redirection
if (process.env.NODE_ENV === 'production') {
app.use (function (req, res, next) {
var schema = (req.headers['x-forwarded-proto'] || '').toLowerCase();
if (schema === 'https') {
next();
} else {
res.redirect('https://' + req.headers.host + req.url);
}
});
}
/** ... more configuration **/
// Default request handler
app.use(function(req, res, next) {
// ... your code
});
// Default error handler
app.use(function(err, req, res, next) {
// ... your code
});