feat(GOV-009): 建立 NestJS 三进程基线
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({})
|
||||
export class ApiModule {}
|
||||
@@ -0,0 +1,34 @@
|
||||
import 'reflect-metadata';
|
||||
|
||||
import { type INestApplication, type NestApplicationOptions } from '@nestjs/common';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
|
||||
import { loadApiProcessConfig } from '../../../libs/config/src/load-process-env';
|
||||
import {
|
||||
toSafeRuntimeSummary,
|
||||
type ApiRuntimeConfig,
|
||||
} from '../../../libs/config/src/runtime-config';
|
||||
import { ApiModule } from './api.module';
|
||||
|
||||
interface BootstrapApiOptions {
|
||||
config: ApiRuntimeConfig;
|
||||
port?: number;
|
||||
logger?: NestApplicationOptions['logger'];
|
||||
}
|
||||
|
||||
export async function bootstrapApi(options: BootstrapApiOptions): Promise<INestApplication> {
|
||||
const app = await NestFactory.create(ApiModule, { logger: options.logger });
|
||||
app.enableShutdownHooks();
|
||||
await app.listen(options.port ?? options.config.api.port, options.config.api.host);
|
||||
return app;
|
||||
}
|
||||
|
||||
async function runApi(): Promise<void> {
|
||||
const config = loadApiProcessConfig();
|
||||
console.info('API 进程启动配置', toSafeRuntimeSummary(config));
|
||||
await bootstrapApi({ config });
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
void runApi();
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.build.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../dist/apps/api"
|
||||
},
|
||||
"include": ["src/**/*.ts", "../../libs/**/*.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user