-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
39 lines (29 loc) · 1.17 KB
/
main.ts
File metadata and controls
39 lines (29 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { NestFactory } from "@nestjs/core";
import { ValidationPipe } from "@nestjs/common";
import { AppModule } from "./app.module";
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const config = new DocumentBuilder()
.setTitle('Orders API')
.setDescription('API documentation for the Orders system')
.setVersion('1.0')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
console.log('Swagger running at http://localhost:3000/api');
app.enableCors({
origin: process.env.CORS_ORIGIN || "*",
credentials: true,
});
// ** 🧩 Enables global validation for all DTOs
app.useGlobalPipes(
new ValidationPipe({
whitelist: true, // automatically removes properties not defined in the DTO class
forbidNonWhitelisted: true, // throws an error if unknown properties are present in the request
transform: true, // converts plain JavaScript objects into instances of their corresponding DTO classes
})
);
await app.listen(process.env.PORT ?? 3000);
}
bootstrap();