是否可以检查express.js 处理程序是否正在使用HTTPS?
有没有办法确定请求是否在带有express的node.js中使用HTTPS?我正在使用 Heroku 及其证书,我假设这些证书安装在负载均衡器上,而不是安装在单个 Web 服务器/实例上。
Is there a way to determine if the request is using HTTPS in node.js with express? I'm using Heroku with their certs which I'm assuming are installed at the load balancer and not on individual web servers/ instances.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您可以配置 nginx,请在 nginx 配置中添加此参数
,然后在代码中检查它并为其他处理程序设置标志。
If you can configure nginx, add this parameter in nginx config
And then in your code check for it and set flag for other handlers.
Express 对 http 和 https 服务器有不同的配置。您是否在同一个应用程序中收听两者?或者只是听一个?
您可以查看 Express 指南以了解如何设置每种服务器类型
http://expressjs.com/guide.html
您可以设置 app = http 和 app2 = https 的内容如果您想从同一个文件中提供两者。
app.get('/server', function(req, res){ console.log('http 请求')});
app2.get('/server', function(req, res){ console.log('https 请求')});
Express has different configurations for http and https servers. Are you listening for both in the same app? or just listening for one?
You could check the Express guide for how to set up each server type
http://expressjs.com/guide.html
You could set something where app = http and app2 = https if you want to serve both from the same file.
app.get('/server', function(req, res){ console.log('http request')});
app2.get('/server', function(req, res){ console.log('https request')});
同样的事情,在我的例子中,nginx 正在处理 ssl,因此我被迫获取客户端信息。在第一页加载时,我提取协议并将其发送到异步节点。
认为这不是一个可靠的解决方案,但在生产中效果出奇的好。
您找到服务器端解决方案了吗?
Same thing here, nginx is handling ssl in my case, therefore I was forced to grab the info client-side. On first page load I extract the protocol and send it to node async.
Thought that wouldn't be a reliable solution, but works surprisingly well in production.
Did you find a server-side solution yet?