【发布时间】:2019-05-09 05:11:45
【问题描述】:
我在这里看到过类似的问题,但到目前为止我还没有找到解决问题的方法——我现在可能有点生气了。
我正在尝试使用 socket.io,到目前为止,我已经建立了一个快速服务器,并在服务器和客户端(socket.io)上运行了 socket.io -客户端)。
不幸的是,当我尝试从客户端与服务器通信时,我立即遇到重复 404 错误:
GET http://localhost:3000/socket.io/?EIO=3&transport=polling&t=MU8YJvg 404 (Not Found)
GET http://localhost:3000/socket.io/?EIO=3&transport=polling&t=MU8YJvg 404 (Not Found)
GET http://localhost:3000/socket.io/?EIO=3&transport=polling&t=MU8YJvg 404 (Not Found)
...
基本上我的 BrowserSync 将在 localhost:3000 运行,而我的 express/socket.io 将在 localhost:8080 运行
我的 express 设置如下所示:
const express = require("express");
const app = express();
const path = require("path");
const proxy = require("http-proxy-middleware");
const http = require("http").Server(app);
const io = require("socket.io").listen(http);
io.on("connection", socket => {
console.log("a user connected: ", socket.id);
});
app.set("port", 8080);
// Attempt to proxy around BrowserSync
app.use(
"/socket-io",
proxy({
target: "http://localhost:8080",
ws: true,
pathRewrite: { "^/socket.io": "/" }
})
);
http.listen(8080, () => {
console.log(`Listening on ${http.address().port}`);
});
webpack.config.js
....
plugins: [
definePlugin,
new BrowserSyncPlugin({
host: process.env.IP || "localhost",
port: process.env.PORT || 3000,
server: {
baseDir: ["./", "./dist"]
}
})
]
...
我正在使用
(dev-deps)
"browser-sync": "^2.26.3",
"browser-sync-webpack-plugin": "^2.2.2",
(deps)
"express": "^4.16.4",
"socket.io": "^2.2.0",
"socket.io-client": "^2.2.0",
我非常感谢您对此提供的任何帮助,因为没有任何意义了。
【问题讨论】:
标签: express socket.io phaser-framework browser-sync