如果在启动时发出请求,NodeJs/Espress/NestJS服务器将不会启动



我有一个在Nodejs上运行Nestjs和Express的服务器。

如果我在服务器启动时提出任何请求,我会收到以下错误,并且无法启动:

Waiting for the debugger to disconnect...
/node_modules/http-proxy/lib/http-proxy/index.js:120
throw err;
^
Error: connect ECONNREFUSED ::1:61903
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -61,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 61903
}

此时,在/nod_module/http proxy/lib/http proxy/index.js:中抛出错误

ProxyServer.prototype.onError = function (err) {
//
// Remark: Replicate node core behavior using EE3
// so we force people to handle their own errors
//
if(this.listeners('error').length === 1) {
throw err;
}
};

我正在用启动服务器

const task = SERVICE_TASK.toUpperCase();
const app = await createApp(task);
app.set('trust proxy', true);
app.enableShutdownHooks();
const {httpAdapter} = app.get(HttpAdapterHost);
app.useGlobalFilters(new ExceptionLogger(httpAdapter));
app.enableCors({origin: '*'});
await app.listen(PORT);

我该如何处理这些错误?

在创建http代理之前添加了以下代码。

import proxy from 'http-proxy';
proxy.prototype.onError = function (err) {
if(this.listeners('error').length === 1) {
console.warn(err);
//   throw err;
}
};

最新更新