【问题标题】:Express / Heroku not redirecting to httpsExpress / Heroku 未重定向到 https
【发布时间】:2018-02-26 08:26:40
【问题描述】:

【问题讨论】:

    标签: express heroku https


    【解决方案1】:

    上述解决方案应该可以正常工作。 Heroku 有问题。它使用某种代理。这段代码 sn-p 应该修复它:

    // require https
    app.use((req, res, next) => {
      if (req.hostname !== 'localhost' && req.get('X-Forwarded-Proto') !== 'https') {
        return res.redirect(`https://${req.hostname}${req.url}`)
      }
      return next()
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-02
      • 1970-01-01
      • 1970-01-01
      • 2014-07-23
      • 1970-01-01
      • 2014-05-14
      相关资源
      最近更新 更多