31 lines
915 B
TypeScript
31 lines
915 B
TypeScript
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/.env(Node 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();
|