48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import { ValidationPipe } from '@nestjs/common';
|
|
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
|
import helmet from 'helmet';
|
|
import { AppModule } from './app.module';
|
|
import { HttpExceptionFilter } from './common/filters/http-exception.filter';
|
|
import { LoggingInterceptor } from './common/interceptors/logging.interceptor';
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create(AppModule);
|
|
|
|
app.setGlobalPrefix('api/v1');
|
|
|
|
app.use(helmet());
|
|
|
|
app.enableCors({
|
|
origin: process.env.CORS_ORIGIN || 'http://localhost:3000',
|
|
credentials: true,
|
|
});
|
|
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
whitelist: true,
|
|
forbidNonWhitelisted: true,
|
|
transform: true,
|
|
}),
|
|
);
|
|
|
|
app.useGlobalFilters(new HttpExceptionFilter());
|
|
app.useGlobalInterceptors(new LoggingInterceptor());
|
|
|
|
const config = new DocumentBuilder()
|
|
.setTitle('KoolTab Remote Tab Control API')
|
|
.setDescription('API for managing remote tab control in venues')
|
|
.setVersion('1.0')
|
|
.addBearerAuth()
|
|
.build();
|
|
|
|
const document = SwaggerModule.createDocument(app, config);
|
|
SwaggerModule.setup('api/docs', app, document);
|
|
|
|
const port = process.env.PORT || 3001;
|
|
await app.listen(port);
|
|
console.log(`API running on http://localhost:${port}`);
|
|
console.log(`Swagger docs at http://localhost:${port}/api/docs`);
|
|
}
|
|
|
|
bootstrap(); |