-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.ts
executable file
·46 lines (38 loc) · 1.25 KB
/
app.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
import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
import { Logger as PinoLogger, LoggerErrorInterceptor } from 'nestjs-pino';
import { middleware } from './app.middleware';
import { AppModule } from './app.module';
import { genReqId } from './config';
async function bootstrap(): Promise<string> {
const isProduction = process.env.NODE_ENV === 'production';
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter({
trustProxy: isProduction,
// Fastify has pino built in, but it use nestjs-pino, so we disable the logger.
logger: false,
// https://github.com/iamolegga/nestjs-pino/issues/1351
genReqId,
}),
{
bufferLogs: isProduction,
},
);
app.useLogger(app.get(PinoLogger));
app.useGlobalInterceptors(new LoggerErrorInterceptor());
// Fastify Middleware
await middleware(app);
app.enableShutdownHooks();
await app.listen(process.env.PORT || 3000);
return app.getUrl();
}
void (async () => {
try {
const url = await bootstrap();
Logger.log(url, 'Bootstrap');
} catch (error) {
Logger.error(error, 'Bootstrap');
}
})();