gpt4 book ai didi

express - 继续获取和发布/socket.io/?EIO=3&transport=polling&t=

转载 作者:行者123 更新时间:2023-12-04 01:21:33 24 4
gpt4 key购买 nike

我在 ExpressJS 和 NodeJS 中的后端曾经运行良好。我刚刚意识到日志爆炸了磁盘(后端仍然可用),因为当后端打开时,它一直在尝试:

kpi.js GET /socket.io/?EIO=3&transport=polling&t=NBiaEK6
index.js GET /socket.io/?EIO=3&transport=polling&t=NBiaEK6
index.js router.get *
kpi.js POST /socket.io/?EIO=3&transport=polling&t=NBiaER6
index.js POST /socket.io/?EIO=3&transport=polling&t=NBiaER6
Error: Not Found
at /opt/funfun/app.js:99:13
at Layer.handle [as handle_request] (/opt/funfun/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/opt/funfun/node_modules/express/lib/router/index.js:317:13)
at /opt/funfun/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/opt/funfun/node_modules/express/lib/router/index.js:335:12)
at next (/opt/funfun/node_modules/express/lib/router/index.js:275:10)
at /opt/funfun/node_modules/express/lib/router/index.js:635:15
at next (/opt/funfun/node_modules/express/lib/router/index.js:260:14)
at /opt/funfun/routes/index.js:18:2
at Layer.handle [as handle_request] (/opt/funfun/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/opt/funfun/node_modules/express/lib/router/index.js:317:13)
at /opt/funfun/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/opt/funfun/node_modules/express/lib/router/index.js:335:12)
at next (/opt/funfun/node_modules/express/lib/router/index.js:275:10)
at Function.handle (/opt/funfun/node_modules/express/lib/router/index.js:174:3)
at router (/opt/funfun/node_modules/express/lib/router/index.js:47:12)
at Layer.handle [as handle_request] (/opt/funfun/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/opt/funfun/node_modules/express/lib/router/index.js:317:13)
at /opt/funfun/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/opt/funfun/node_modules/express/lib/router/index.js:335:12)
at next (/opt/funfun/node_modules/express/lib/router/index.js:275:10)
at /opt/funfun/node_modules/express/lib/router/index.js:635:15
kpi.js GET /socket.io/?EIO=3&transport=polling&t=NBiaF8A
index.js GET /socket.io/?EIO=3&transport=polling&t=NBiaF8A
index.js router.get *
kpi.js POST /socket.io/?EIO=3&transport=polling&t=NBiaFFz
index.js POST /socket.io/?EIO=3&transport=polling&t=NBiaFFz
Error: Not Found
at /opt/funfun/app.js:99:13
at Layer.handle [as handle_request] (/opt/funfun/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/opt/funfun/node_modules/express/lib/router/index.js:317:13)
at /opt/funfun/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/opt/funfun/node_modules/express/lib/router/index.js:335:12)
at next (/opt/funfun/node_modules/express/lib/router/index.js:275:10)
at /opt/funfun/node_modules/express/lib/router/index.js:635:15
at next (/opt/funfun/node_modules/express/lib/router/index.js:260:14)
at /opt/funfun/routes/index.js:18:2
at Layer.handle [as handle_request] (/opt/funfun/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/opt/funfun/node_modules/express/lib/router/index.js:317:13)
at /opt/funfun/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/opt/funfun/node_modules/express/lib/router/index.js:335:12)
at next (/opt/funfun/node_modules/express/lib/router/index.js:275:10)
at Function.handle (/opt/funfun/node_modules/express/lib/router/index.js:174:3)
at router (/opt/funfun/node_modules/express/lib/router/index.js:47:12)
at Layer.handle [as handle_request] (/opt/funfun/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/opt/funfun/node_modules/express/lib/router/index.js:317:13)
at /opt/funfun/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/opt/funfun/node_modules/express/lib/router/index.js:335:12)
at next (/opt/funfun/node_modules/express/lib/router/index.js:275:10)
at /opt/funfun/node_modules/express/lib/router/index.js:635:15

kpi.js GET ...index.js GET ... 是我打印的。这是 opt/funfun/app.js 的代码:

// catch 404 and forward to error handler
app.use(function (req, res, next) {
var err = new Error('Not Found'); // line 99
err.status = 404;
next(err);
});

谁知道可能是什么原因?

最佳答案

如果您有一个 socket.io 客户端尝试连接到,则可能会发生这种情况您的后端,但您的后端没有配置 socket.io 服务器或未正确配置为接受连接并且您正在记录任何错误错误处理程序。

确保正确配置了 socket.io 客户端和服务器。请参阅socket.io docs关于如何设置客户端和服务器。

默认情况下,客户端会在连接失败时无限尝试重新连接,您可以通过设置来防止它无限轮询服务器 reconnectionAttempts选项。

例如,这将阻止客户端在 10 次尝试失败后轮询服务器

const socket = io(serverURL, { reconnectionAttempts: 10 });

另外,为了尽量减少日志的大小,当您处于生产时,不要记录整个错误object,您可以更新错误处理程序以仅记录相关详细信息

// catch errors and forward to error handler
app.use(function (req, res, next) {
...
next(err);
});

//In the error handler
app.use(function (err, req, res, next) {
//log only relevant details
logger.info(err.message)
})

关于express - 继续获取和发布/socket.io/?EIO=3&transport=polling&t=,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62581662/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com