-
Notifications
You must be signed in to change notification settings - Fork 78
/
main.ts
56 lines (45 loc) · 1.68 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { ConfigService } from '@nestjs/config';
import { AppModule } from './app.module';
import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
import * as multipart from 'fastify-multipart';
import { ResponseFormatInterceptor } from '@samagra-x/stencil';
import { Logger } from '@nestjs/common';
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(),
);
// Example of setting up a logger
const logger = new Logger('Main'); // 'Main' is the context name
const configService = app.get(ConfigService);
const port = configService.get<number>('port');
const host = configService.get<string>('host');
const method = configService.get<string>('method');
// Register plugins and middleware
await app.register(multipart);
// Global setup
app.useGlobalInterceptors(new ResponseFormatInterceptor());
app.useGlobalPipes(new ValidationPipe());
// Swagger API documentation setup
const options = new DocumentBuilder()
.setTitle('GeoQuery.In')
.setDescription('Demo')
.setVersion('1.0')
.addServer('http://localhost:3000/', 'Local environment')
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('api-docs', app, document);
// Start the server
await app.listen(port, host, (err, address) => {
logger.log(`Server running on ${method}://${host}:${port}`);
});
// Log additional information as needed
logger.log('Application started');
}
bootstrap();