student-manage/apps/server/src/main.ts

31 lines
869 B
TypeScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { TrpcRouter } from './trpc/trpc.router';
import { WebSocketService } from './socket/websocket.service';
async function bootstrap() {
// 创建NestJS应用实例
const app = await NestFactory.create(AppModule);
// 启用 CORS 并允许所有来源
app.enableCors({
origin: '*',
});
// 获取WebSocket服务实例并初始化
const wsService = app.get(WebSocketService);
await wsService.initialize(app.getHttpServer());
// 获取tRPC路由实例并应用中间件
const trpc = app.get(TrpcRouter);
trpc.applyMiddleware(app);
// 设置服务器端口优先使用环境变量中的值默认3000
const port = process.env.SERVER_PORT || 3000;
// 启动应用,监听指定端口
await app.listen(port);
}
// 启动应用
bootstrap();