From 8f3d14ef68de4ac2355997acc4a28134b2158c0e Mon Sep 17 00:00:00 2001 From: wanwu Date: Tue, 14 Oct 2025 22:40:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20niucloud-php=20?= =?UTF-8?q?=E5=92=8C=20niucloud-java=20=E5=AF=B9=E6=A0=87=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=EF=BC=8C=E5=AE=8C=E5=96=84=E5=81=A5=E5=BA=B7=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 niucloud-php 对标项目用于业务逻辑参考 - 添加 niucloud-java 对标项目用于架构设计参考 - 完善 NestJS 健康检查模块 - 更新 Docker 启动脚本 - 优化模块导入配置 --- wwjcloud-nest/docker/start-all.sh | 0 wwjcloud-nest/src/common/common.module.ts | 3 + .../src/common/health/health.controller.ts | 62 +++++++++++++++++++ .../src/common/health/health.module.ts | 13 ++++ wwjcloud-nest/src/main.ts | 4 +- 5 files changed, 81 insertions(+), 1 deletion(-) mode change 100644 => 100755 wwjcloud-nest/docker/start-all.sh create mode 100644 wwjcloud-nest/src/common/health/health.controller.ts create mode 100644 wwjcloud-nest/src/common/health/health.module.ts diff --git a/wwjcloud-nest/docker/start-all.sh b/wwjcloud-nest/docker/start-all.sh old mode 100644 new mode 100755 diff --git a/wwjcloud-nest/src/common/common.module.ts b/wwjcloud-nest/src/common/common.module.ts index 5253f1cc..8f5fe670 100644 --- a/wwjcloud-nest/src/common/common.module.ts +++ b/wwjcloud-nest/src/common/common.module.ts @@ -13,6 +13,7 @@ import { InitModule } from './init/init.module'; import { ContextModule } from './context/context.module'; // import { SwaggerModule } from './swagger/swagger.module'; import { DatabaseModule } from './database/database.module'; +import { HealthModule } from './health/health.module'; // import { ValidationModule } from './validation/validation.module'; // 已合并到 PipesModule import { ResponseModule } from './response/response.module'; import { UtilsModule } from './utils/utils.module'; @@ -46,6 +47,7 @@ import { PluginsModule } from './plugins/plugins.module'; QueueModule, // 队列服务 EventModule, // 事件服务 ResponseModule, // 响应处理 + HealthModule, // 健康检查服务 // 自研工具类 UtilsModule, @@ -79,6 +81,7 @@ import { PluginsModule } from './plugins/plugins.module'; QueueModule, EventModule, ResponseModule, + HealthModule, // 自研工具类 UtilsModule, diff --git a/wwjcloud-nest/src/common/health/health.controller.ts b/wwjcloud-nest/src/common/health/health.controller.ts new file mode 100644 index 00000000..f640fa54 --- /dev/null +++ b/wwjcloud-nest/src/common/health/health.controller.ts @@ -0,0 +1,62 @@ +import { Controller, Get } from '@nestjs/common'; +import { ApiTags, ApiOperation } from '@nestjs/swagger'; +import { Public } from '@wwjCommon/security/decorators/public.decorator'; +import { InitService } from '../init/init.service'; +import { MonitoringService } from '../monitoring/monitoring.service'; + +/** + * 健康检查控制器 + * 提供应用健康状态检查端点 + */ +@ApiTags('health') +@Controller('health') +export class HealthController { + constructor( + private readonly initService: InitService, + private readonly monitoringService: MonitoringService, + ) {} + + /** + * 健康检查端点 + * 路由: GET /health/status + */ + @Get('status') + @Public() + @ApiOperation({ summary: '健康检查' }) + async health() { + try { + // 获取基础健康状态 + const basicHealth = this.initService.getHealthStatus(); + + // 获取详细监控信息 + const detailedHealth = await this.monitoringService.check(); + + return { + ...basicHealth, + ...detailedHealth, + timestamp: new Date().toISOString(), + }; + } catch (error) { + return { + status: 'unhealthy', + error: error.message, + timestamp: new Date().toISOString(), + }; + } + } + + /** + * 简单健康检查端点 + * 路由: GET /ping + */ + @Get('ping') + @Public() + @ApiOperation({ summary: '简单健康检查' }) + async ping() { + return { + status: 'ok', + timestamp: new Date().toISOString(), + uptime: process.uptime(), + }; + } +} \ No newline at end of file diff --git a/wwjcloud-nest/src/common/health/health.module.ts b/wwjcloud-nest/src/common/health/health.module.ts new file mode 100644 index 00000000..7e4a2932 --- /dev/null +++ b/wwjcloud-nest/src/common/health/health.module.ts @@ -0,0 +1,13 @@ +import { Module } from '@nestjs/common'; +import { HealthController } from './health.controller'; +import { InitModule } from '../init/init.module'; +import { MonitoringModule } from '../monitoring/monitoring.module'; + +/** + * 健康检查模块 + */ +@Module({ + imports: [InitModule, MonitoringModule], + controllers: [HealthController], +}) +export class HealthModule {} \ No newline at end of file diff --git a/wwjcloud-nest/src/main.ts b/wwjcloud-nest/src/main.ts index fddd7e13..1faca22d 100644 --- a/wwjcloud-nest/src/main.ts +++ b/wwjcloud-nest/src/main.ts @@ -9,6 +9,8 @@ async function bootstrap() { // const swaggerService = app.get(SwaggerService); // swaggerService.setupSwagger(app); - await app.listen(process.env.PORT ?? 3001); + const port = parseInt(process.env.APP_PORT || '3000'); + console.log(`Application is starting on port: ${port}`); + await app.listen(port); } bootstrap();