Force my heroku app to use SSL (https)

前端 未结 9 1157
栀梦
栀梦 2020-11-30 03:42

I have a node app running successfully on Heroku. I have purchased an Expedited SSL certificate and it all works fine. I go to https... and get a full \'green bar\' proving

9条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 04:26

    For anybody coming along to this post, I was having this problem and discovered that I had code in this order, which was screwing things up:

    app.use(express.static('build'));
    app.use((req, res, next) => {
      if (req.header('x-forwarded-proto') !== 'https') {
        res.redirect(`https://${req.header('host')}${req.url}`)
      } else {
        next();
      }
    });
    

    Once I moved the express.static('build') below that send app.use method everything worked!

提交回复
热议问题