本文介绍了如何在express中设置websocket服务器的路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的设置与此类似:

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 /不管。问题是如何设置路径?有可能吗?

I would like to put the WebSocketServer under a specific path which may for instance be "...com/whatever". The question is how can I set the path? Is it possible?

推荐答案

你想要使用路径选项:

var wss = new WebSocketServer({server: server, path: "/hereIsWS"});

查看完整文档

这篇关于如何在express中设置websocket服务器的路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 11:31