Files
Train/apps/api/src/main.ts
T
2026-06-16 00:55:20 +08:00

31 lines
915 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { NestFactory } from '@nestjs/core';
import { ValidationPipe, Logger } from '@nestjs/common';
import * as express from 'express';
import { AppModule } from './app.module';
import { uploadDir, PUBLIC_PREFIX } from './photos/uploads';
// 加载 apps/api/.envNode 20.12+/22 内置;缺失时忽略)
try {
(process as any).loadEnvFile?.();
} catch {
/* 没有 .env 文件时忽略 */
}
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(
new ValidationPipe({
transform: true,
whitelist: true,
forbidNonWhitelisted: false,
}),
);
app.enableCors();
// 静态服务上传的图片(共享图库)
app.use(PUBLIC_PREFIX, express.static(uploadDir()));
const port = process.env.PORT || 3001;
await app.listen(port);
new Logger('Bootstrap').log(`API 已启动: http://localhost:${port}/api/health`);
}
bootstrap();