-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmain.ts
More file actions
27 lines (23 loc) · 988 Bytes
/
main.ts
File metadata and controls
27 lines (23 loc) · 988 Bytes
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
import { NestFactory } from '@nestjs/core';
import { Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { FastifyAdapter, type NestFastifyApplication } from '@nestjs/platform-fastify';
import { AppModule } from './app/app.module.js';
import { setupSwagger, enableCors, enableCompression } from './setup.js';
const logger = new Logger('Main', { timestamp: true });
/**
* 启动服务
*/
async function bootstrap(): Promise<void> {
logger.log(`App starting`);
const app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter(), {});
enableCors(app);
setupSwagger(app);
await enableCompression(app);
const config = app.get(ConfigService);
const port = Number.parseInt(config.get<string>('PORT', '3000'));
await app.listen(port, '0.0.0.0');
const url = await app.getUrl();
Logger.log(`App start listening on ${url}`, 'Main');
}
bootstrap().catch((err: unknown) => logger.error(err));