32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import 'dotenv/config';
|
||
import { NestFactory } from '@nestjs/core';
|
||
import { ValidationPipe } from '@nestjs/common';
|
||
import { Logger } from 'nestjs-pino';
|
||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||
import { AppModule } from './app.module.js';
|
||
|
||
async function bootstrap(): Promise<void> {
|
||
const app = await NestFactory.create(AppModule, { bufferLogs: true });
|
||
app.setGlobalPrefix('api/v1');
|
||
app.enableCors();
|
||
app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
|
||
app.useLogger(app.get(Logger));
|
||
|
||
const swaggerConfig = new DocumentBuilder()
|
||
.setTitle('系统管理 API')
|
||
.setDescription('投云科技系统管理 API 文档')
|
||
.setVersion('1.0')
|
||
.addBearerAuth()
|
||
.build();
|
||
SwaggerModule.setup(
|
||
'docs',
|
||
app,
|
||
SwaggerModule.createDocument(app, swaggerConfig),
|
||
);
|
||
|
||
const port = Number(process.env.PORT ?? 3000);
|
||
await app.listen(port);
|
||
app.get(Logger).log(`服务启动成功,端口 ${port},Swagger 文档: http://localhost:${port}/docs`);
|
||
}
|
||
await bootstrap();
|