0

我的nestjs WebSocketGateway 服务器在开发模式下运行良好,但在生产模式下我可以看到那些试图连接但服务器引发以下异常的客户端2022-02-08T08:33:33.901Z undefined ERROR No exports found in module "../dist/main.js". 2022-02-08T08:33:33.901Z undefined ERROR Did you forget to export a function or a server? RequestId: 9186e127-dbdd-4a1a-988c-dbfa0521b37c Error: Runtime exited with error: exit status 1 Runtime.ExitError

这是我的代码 import { SubscribeMessage, WebSocketGateway, WebSocketServer, } from '@nestjs/websockets'; import { Server } from 'socket.io'; @WebSocketGateway({ transports: ['websocket', 'polling'], cors: { origin: '*', methods: ['GET', 'POST'], } }) export class EventsGateway { @WebSocketServer() server: Server;

和我的模块在这里

import { Module } from '@nestjs/common';
import { EventsGateway } from './events.gateway';

@Module({
providers: [EventsGateway],
})
export class EventsModule {}.

然后是我的 main.ts

const app = await NestFactory.create(AppModule);
app.setGlobalPrefix('api');
app.use(bodyParser.json({ limit: '900mb' }));
app.use(
bodyParser.urlencoded({
limit: '900mb',
extended: true,
}),
);
app.enableCors({
origin: function (origin, callback) {
if (!origin || allowed.indexOf(origin) !== -1) {
callback(null, true)
} else {
callback(new Error('Not allowed by CORS'))
}
},
});
await app.listen(process.env.PORT || 8080);
console.log(`your app is running on ${await app.getUrl()}`)

这里是服务器端点 const ENDPOINT 'https://backendsejour.vercel.app/'; 以及我如何使用它来连接它,它可以在本地工作,但生产不能导出 const socket = socketIOClient(ENDPOINT);

4

0 回答 0