fix(GOV-009): 完成脚手架审查整改
This commit is contained in:
@@ -2,6 +2,7 @@ import 'reflect-metadata';
|
||||
|
||||
import { type INestApplication, type NestApplicationOptions } from '@nestjs/common';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import path from 'node:path';
|
||||
|
||||
import { loadApiProcessConfig } from '../../../libs/config/src/load-process-env';
|
||||
import {
|
||||
@@ -10,14 +11,18 @@ import {
|
||||
} from '../../../libs/config/src/runtime-config';
|
||||
import { ApiModule } from './api.module';
|
||||
|
||||
/** API 引导参数只接受已完成进程级校验的配置,测试可覆盖监听端口和日志器。 */
|
||||
interface BootstrapApiOptions {
|
||||
config: ApiRuntimeConfig;
|
||||
port?: number;
|
||||
logger?: NestApplicationOptions['logger'];
|
||||
}
|
||||
|
||||
/** 启动可独立部署的 API;配置由入口显式注入,监听前已完成全部校验。 */
|
||||
export async function bootstrapApi(options: BootstrapApiOptions): Promise<INestApplication> {
|
||||
const app = await NestFactory.create(ApiModule, { logger: options.logger });
|
||||
const app = await NestFactory.create(ApiModule.register(options.config), {
|
||||
logger: options.logger,
|
||||
});
|
||||
app.setGlobalPrefix('api/v1');
|
||||
app.enableShutdownHooks();
|
||||
await app.listen(options.port ?? options.config.api.port, options.config.api.host);
|
||||
@@ -30,6 +35,6 @@ async function runApi(): Promise<void> {
|
||||
await bootstrapApi({ config });
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
if (process.argv[1] && path.resolve(process.argv[1]) === path.resolve(__filename)) {
|
||||
void runApi();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user