node.js - 将 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
}
});
解决方案
推荐阅读
- python - 尝试通过网状包在 R 中使用 Python Gekko 时出错
- tfs - TFS2015 看不到项目文件,不能签入任何东西
- oracle - 我可以在 Oracle 数据库的 EXCEPTION 处理程序中获取 SQLSTATE 值吗?
- c++ - rapidjson 擦除数组并释放内存
- php - PhpStorm 调试问题
- openssl - OpenSSL 编译错误未定义参考
- android - Kotlin DSL Android 库的共享文件
- laravel - 使用 Woocommerce REST API“自动/woocommerce”上传图像时“抱歉,出于安全原因,不允许使用此文件类型”
- php - 如何在给定的特定时间运行 php 脚本而不使用 cron 作业和打开网页?
- java - 线程在调用方法之后但在方法的第一条指令之前会失去控制吗?