crystelf-core/src/main.ts
2025-08-26 17:58:36 +08:00

45 lines
1.7 KiB
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 { AppModule } from './app.module';
import { Logger, RequestMethod } from '@nestjs/common';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { ResponseInterceptor } from './common/interceptors/response.interceptor';
import { AllExceptionsFilter } from './common/filters/all-exception.filter';
import { SystemService } from './core/system/system.service';
import { WsAdapter } from '@nestjs/platform-ws';
async function bootstrap() {
Logger.log('晶灵核心初始化..');
const app = await NestFactory.create(AppModule);
app.setGlobalPrefix('api', {
exclude: [
'cdn',
{ path: 'cdn/(.*)', method: RequestMethod.ALL },
'public',
{ path: 'public/(.*)', method: RequestMethod.ALL },
],
});
app.useGlobalInterceptors(new ResponseInterceptor());
app.useGlobalFilters(new AllExceptionsFilter());
const systemService = app.get(SystemService);
const restartDuration = systemService.checkRestartTime();
if (restartDuration) {
new Logger('System').warn(`重启完成!耗时 ${restartDuration}`);
}
const config = new DocumentBuilder()
.setTitle('晶灵核心')
.setDescription('为晶灵提供API服务')
.setVersion('1.0')
.build();
const document = () => SwaggerModule.createDocument(app, config);
SwaggerModule.setup('docs', app, document);
app.useWebSocketAdapter(new WsAdapter(app));
await app.listen(6868);
await systemService.checkUpdate().catch((err) => {
Logger.error(`自动更新失败: ${err?.message}`, '', 'System');
});
}
bootstrap().then(() => {
Logger.log(`API服务已启动http://localhost:7000/api`);
Logger.log(`API文档 http://localhost:7000/docs`);
});