Repository navigation
Expand file tree
/
Copy pathmain.ts
More file actions
54 lines (46 loc) · 1.53 KB
/
Copy pathmain.ts
File metadata and controls
54 lines (46 loc) · 1.53 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* This is not a production server yet!
* This is only a minimal backend to get started.
*/
import { Logger, ValidationPipe } from '@nestjs/common';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors();
const globalPrefix = 'api';
app.setGlobalPrefix(globalPrefix);
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
}),
);
const swaggerEnabled = process.env.SWAGGER_ENABLED?.toLowerCase() === 'true';
if (swaggerEnabled) {
const config = new DocumentBuilder()
.setTitle('[YOUR_APP_NAME] API Docs')
.setDescription('Documentation for [YOUR_APP_NAME] API routes')
.addBearerAuth({
type: 'http',
description:
'[TL] Replace: how clients obtain a Bearer token for this API.',
})
.addTag('Users', 'Operations on users')
.setVersion('1.0')
.build();
const document = SwaggerModule.createDocument(app, config); // Create the Swagger document
SwaggerModule.setup('api', app, document); // Setup the Swagger module
Logger.log(
`😎 Swagger is enabled and will be available at: http://localhost:${
process.env.PORT || 3000
}/api`,
);
}
const port = process.env.PORT || 3000;
await app.listen(port);
Logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`,
);
}
bootstrap();