【问题标题】:Redirecting Heroku NodeJS app to https将 Heroku NodeJS 应用程序重定向到 https
【发布时间】:2018-05-12 08:16:01
【问题描述】:

我有一个带有自动证书管理功能的 Heroku 应用。我已经检查了如何使用 req.headers['x-forwarded-proto'] 重定向到 https,但是我在该字段中得到了“https”而不是“http”,并且我的应用程序没有重定向到 https。我在 DNS Made Easy 中有 DNS。浏览器从根域和子域重定向到 https 应该怎么做?

【问题讨论】:

    标签: node.js express heroku https


    【解决方案1】:
    // 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();
      }
    });
    

    这会将来自http的所有请求重定向到https

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-27
      • 1970-01-01
      • 2018-08-21
      • 2018-10-12
      • 2019-11-13
      • 2018-09-20
      • 2011-11-03
      • 1970-01-01
      相关资源
      最近更新 更多