我正在尝试在heroku上运行我的node js应用程序。这次我解决了所有问题,但是可以通过两种方式解决:
是否可以让heroku在经典http:// ...而非https:// ...上为我的应用程序提供服务?
如果没有
当我尝试连接到ws://gofishy.heroku.com时,它说这VM153:35 Mixed Content: The page at 'https://gofishy.herokuapp.com/' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'gofishy.heroku.com'. This request has been blocked; this endpoint must be available over WSS.
还有这个
Uncaught SecurityError: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.
我试图这样连接:
var ws = new WebSocket("ws://" + server);
在
server = 'gofishy.herokuapp.com'
的地方,在服务器上,我有这个:var WebSocketServer = require('ws').Server;
var wss = new WebSocketServer({ server: server });
我可以将某些内容传递给
new WebsocketServer
作为参数以使其通过SSL起作用吗? 最佳答案
我应该这样做:
var ws = new WebSocket("wss://" + server);
代替这个:
var ws = new WebSocket("ws://" + server);
注意带有两个
wss
的s
。