forked from CatsMiaow/nestjs-project-structure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
executable file
·46 lines (38 loc) · 1.24 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 as NestLogger, ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import type { NestExpressApplication } from '@nestjs/platform-express';
import { middleware } from './app.middleware';
import { AppModule } from './app.module';
import { Logger } from './common';
/**
* 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(await app.resolve(Logger));
// https://docs.nestjs.com/techniques/validation
app.useGlobalPipes(new ValidationPipe({
disableErrorMessages: true,
transform: true, // transform object to DTO class
}));
if (isProduction) {
app.enable('trust proxy');
}
// Express Middleware
middleware(app);
await app.listen(process.env.PORT || 3000);
return app.getUrl();
}
(async (): Promise<void> => {
try {
const url = await bootstrap();
NestLogger.log(url, 'Bootstrap');
} catch (error) {
NestLogger.error(error, 'Bootstrap');
}
})();