我有一个与此类似的设置:
var WebSocketServer = require("ws").Server, express = require("express"), http = require("http"), app = express(), server = http.createServer(app); app.post("/login", login); app.get("/...", callSomething); // ... server.listen(8000); var wss = new WebSocketServer({server: server}); wss.on("connection", function(ws){ // ... });
我想将WebSocketServer放在特定的路径下,例如"...com/whatever"。问题是如何设置路径?可能吗?
"...com/whatever"
您将要使用以下path选项:
path
var wss = new WebSocketServer({server: server, path: "/hereIsWS"});
在此处查看完整文档