Files
corrosion-admin-panel/backend-nest/src/main.ts
Vantz Stockwell 14b099b075
All checks were successful
Test Asgard Runner / test (push) Successful in 3s
fix: Replace socket.io with native WS adapter — fixes WebSocket 1006
Frontend uses native WebSocket API, backend was using socket.io which
speaks an incompatible protocol. Switched to @nestjs/platform-ws so
both sides speak native WebSocket. Also fixed JWT TTL override in
docker-compose.yml (was hardcoded to 900s, now 14400s/4h).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 15:21:36 -05:00

55 lines
1.6 KiB
TypeScript

import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { WsAdapter } from '@nestjs/platform-ws';
import { AppModule } from './app.module';
import { HttpExceptionFilter } from './common/filters/http-exception.filter';
import { TransformInterceptor } from './common/interceptors/transform.interceptor';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
// Use native WebSocket adapter (not socket.io)
app.useWebSocketAdapter(new WsAdapter(app));
// Global prefix — all routes under /api
app.setGlobalPrefix('api');
// Global validation pipe
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
forbidNonWhitelisted: true,
transform: true,
transformOptions: { enableImplicitConversion: true },
}),
);
// Global exception filter
app.useGlobalFilters(new HttpExceptionFilter());
// Global response transform
app.useGlobalInterceptors(new TransformInterceptor());
// CORS
app.enableCors({
origin: process.env.FRONTEND_URL || 'http://localhost:5174',
credentials: true,
});
// Swagger
const swaggerConfig = new DocumentBuilder()
.setTitle('Corrosion API')
.setDescription('Corrosion Admin Panel — Game Server Management Platform')
.setVersion('1.0')
.addBearerAuth()
.build();
const document = SwaggerModule.createDocument(app, swaggerConfig);
SwaggerModule.setup('api/docs', app, document);
const port = process.env.API_PORT || 3000;
await app.listen(port);
console.log(`Corrosion API running on port ${port}`);
}
bootstrap();