ant*_*ant 12
我也部署在Heroku上.当他们使用nginx反向代理时,他们会添加一堆标题.在这种情况下感兴趣的是x-forwarded-proto.
这就是我做的:
app.get(/\/register$/, function(req, res){
console.log(JSON.stringify(req.headers)); //to see all headers that heroku adds
if(req.headers['x-forwarded-proto'] && req.headers['x-forwarded-proto'] === "http") {
res.redirect("https://" + req.headers.host + req.url);
}
else {
//the rest of your logic to handle this route
}
});
Run Code Online (Sandbox Code Playgroud)