-
Notifications
You must be signed in to change notification settings - Fork 230
/
app.ts
executable file
·43 lines (35 loc) · 1.15 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
import { Logger as NestLogger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import type { NestExpressApplication } from '@nestjs/platform-express';
import { Logger, LoggerErrorInterceptor } from 'nestjs-pino';
import { middleware } from './app.middleware';
import { AppModule } from './app.module';
/**
* https://docs.nestjs.com
* https://github.com/nestjs/nest/tree/master/sample
* https://github.com/nestjs/nest/issues/2249#issuecomment-494734673
*/
async function bootstrap(): Promise<string> {
const isProduction = process.env.NODE_ENV === 'production';
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
bufferLogs: true,
});
app.useLogger(app.get(Logger));
app.useGlobalInterceptors(new LoggerErrorInterceptor());
if (isProduction) {
app.enable('trust proxy');
}
// Express Middleware
middleware(app);
app.enableShutdownHooks();
await app.listen(process.env.PORT || 3000);
return app.getUrl();
}
void (async (): Promise<void> => {
try {
const url = await bootstrap();
NestLogger.log(url, 'Bootstrap');
} catch (error) {
NestLogger.error(error, 'Bootstrap');
}
})();