Heroku在负载均衡器级别终止SSL连接,因此
req.secure永远不会成立,因为您到heroku的负载均衡器的连接未使用SSL,因此创建了无限重定向循环。
您必须改为检查
X-Forwarded-Proto标题:
if(req.headers["x-forwarded-proto"] === "https"){ // OK, continue return next();};res.redirect('https://'+req.hostname+req.url);编辑:您还可以设置
app.enable("trustproxy")为自动检查标题。参见http://expressjs.com/guide/behind-proxies.html



