[英]Redirecting Heroku NodeJS app to https
I have a Heroku app with Automated Certificate Management. 我有一个带有自动证书管理的Heroku应用程序。 I already checked how to redirect to https with req.headers['x-forwarded-proto'] but I'm getting 'https' in that field instead of 'http' and my app is not redirecting to https.
我已经检查了如何使用req.headers ['x-forwarded-proto']重定向到https,但是在该字段中获得的是'https'而不是'http',并且我的应用程序未重定向到https。 I have DNS in DNS Made Easy.
我在DNS轻松中拥有DNS。 What should I do to make a redirection from root domain and subdomain to https in web browser?
如何在网络浏览器中从根域和子域重定向到https?
// Redirect http to https
app.get('*', (req, res, next) => {
if (req.headers['x-forwarded-proto'] != 'https'){
res.redirect('https://' + req.hostname + req.url);
} else {
next();
}
});
This will redirect all the requests coming from http to https 这会将所有来自http的请求重定向到https
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.