我在 NodeJS 应用程序中使用 socket.io
。 socket.io
页面位于 localhost:8081/socket.io/
。但是,我想把它放在 localhost:8081/hola/socket.io/
中。那可能吗?
var express = require("express");
var app = express();
var server = require("http").Server(app);
var io = require("socket.io")(server);
//some code here...
server.listen(8081, function() {
console.log("Server running at http://localhost:8081/");
});
最佳答案
只需将 path
传入 options 数组,这是 socket.io
的第二个选项:
var io = require("socket.io")(server, { path: '/hola/socket.io'});
关于node.js - NodeJS 中的 Socket.io,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35337931/