WebSocket安全本地主机连接 [英] WebSocket Secure localhost connection
问题描述
我已经构建了一个简单的节点.js WebSocket聊天服务器.
I've built a simple Node.js WebSocket chat server.
我可以在终端选项卡的localhost
上运行它.
I can run it on localhost
in a terminal tab.
在另一个终端选项卡中,我可以使用ws://
通过wscat
连接到它.
In another terminal tab, I can connect to it with wscat
, using ws://
.
如何使用wss://
在localhost
上连接到它?
How do I connect to it on localhost
with wss://
?
推荐答案
Look at this example code for how to establish an HTTPS server which will handle the TCP and TLS layers and then the ws
module can handle the websocket aspects integrating with that server. You'll need a TLS certificate. For development you can generate your own and sign it yourself. A web search for "self-signed certificate" should lead you to the info you need for that part.
这篇关于WebSocket安全本地主机连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!