首页 > 解决方案 > 将 http 请求转发到 https,req.secure 不起作用

问题描述

每当我使用 HTTP 访问 URL 时,它都不会重定向。

server.js:

app.get('/', function(req,res) {
  console.log('get react app');
  if (req.secure) {
    res.sendFile(path.join(__dirname, '../build', 'index.html')); 
  }
  else {
    res.redirect(URL);//URL with HTTPS
  }
});

标签: node.jsexpress

解决方案


推荐阅读