-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.ts
38 lines (34 loc) · 1.16 KB
/
main.ts
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
import { NestFactory, Reflector } from '@nestjs/core';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import * as cookieParser from 'cookie-parser';
import { JwtAuthGuard } from './core/guards/jwt-auth.guard';
import { configuration } from './core/config/configuration';
import { OfflineModeGuard } from './core/guards/offline-mode.guard';
const PORT = process.env.PORT || 3000;
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const offlineMode = configuration().offlineMode;
app.use(cookieParser());
app.enableCors({
credentials: true,
origin: true,
});
const reflector = app.get(Reflector);
app.useGlobalGuards(
new JwtAuthGuard(reflector),
offlineMode ? new OfflineModeGuard(reflector) : undefined,
);
if (!offlineMode) {
const config = new DocumentBuilder()
.setTitle('OTOG API')
.setDescription('API service for OTOG')
.setVersion('1.0')
.addBearerAuth()
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('doc', app, document);
}
await app.listen(PORT);
}
bootstrap();