[英]How do I test https on socket.io locally?
I've implemented an application using socket.io. 我已经使用socket.io实现了一个应用程序。 All working nicely.
一切都很好。 Converting it to a progressive web app required SSL so I've done that and that's working nicely.
将其转换为渐进式Web应用程序需要SSL,因此我做到了,而且效果很好。 The app installs as a web app and works.
该应用程序将作为网络应用程序安装并运行。
My problem is that when I go back to work on new features, the local installation of the app server ignores my secure client requests (On the production system, nginx handles the SSL). 我的问题是,当我重新使用新功能时,应用服务器的本地安装会忽略我的安全客户端请求(在生产系统上,nginx处理SSL)。
These are the offending lines in the client: 这些是客户端中令人反感的行:
const socket_url = 'https://' + url.hostname + ':' + port;
const socket = openSocket(socket_url, {query: 'clientId=' + clientId, secure: true});
I could edit the relevant line in the client conditionally on production versus local development but I'm hoping there is a more elegant solution. 我可以根据生产条件还是本地开发条件在客户中编辑相关的生产线,但是我希望有一个更优雅的解决方案。
A couple ideas for dealing with the test environment vs. production environment issue: 处理测试环境与生产环境问题的一些想法:
http://
instead of https://
in the code you show in your question so the client would just automatically use the desired protocol (https in production and http in test). http://
而不是https://
,因此客户端将自动使用所需的协议(生产环境中使用https,测试)。 This could be done with a template engine or could be done manually with search/replace when serving the relevant script. location.protocol
instead of a hard code https
which will then automatically use the protocol that the web page was loaded from which could then be either http or https. location.protocol
代替硬代码https
,然后将自动使用从中加载网页的协议,该协议可以是http或https。 So, if the web page is loaded via http, then socket.io would use http.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.