我有一个工作的基于node.js表示的服务器(和客户端)应用程序这里,它在http+websockets上显示RPC。当在本地运行(使用devcontainers)并包括Dockerfile和devcontainer.json时,这是非常有效的。但是,当从codespace运行时,它会在以下客户端错误消息中失败.
client.js:9 Mixed Content:
The page at 'https://aniongithub-jsonrpc-bidirectional-example-<redacted>-8080.preview.app.github.dev/'
was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint
'ws://aniongithub-jsonrpc-bidirectional-example-<redacted>-8080.preview.app.github.dev/api'.
This request has been blocked; this endpoint must be available over WSS.
(anonymous) @ client.js:9
client.js:9 Uncaught DOMException: Failed to construct 'WebSocket':
An insecure WebSocket connection may not be initiated from a page loaded over HTTPS
at 'https://aniongithub-jsonrpc-bidirectional-example-<redacted>-8080.preview.app.github.dev/client.js:9:10'文档这里声明By default, GitHub Codespaces forwards ports using HTTP but you can update any port to use HTTPS, as needed。当我检查所指示的设置时:

它设置为http。我在这里错过了什么?如何让它在http上服务于我的http应用程序?
注意:我的意图是,当本地克隆并在dev容器中打开时,代码的工作方式就像在CodeSpace中打开一样。这意味着我需要确保CodeSpaces生成的证书以某种方式被考虑到本地dev容器进程中,或者我完全放弃了身份验证。或者,我需要知道我是否在CodeSpaces上运行,并做不同的事情,这看起来很混乱,不应该是这样的。希望这能让我问这个问题的意图更清楚!
发布于 2022-11-17 06:04:13
结果是,在运行http时,我无法使用https端点,因此解决方案将根据当前协议使用location.protocol和ws/wss来初始化客户端RPC端点。
https://stackoverflow.com/questions/74258122
复制相似问题