feat: 添加 niucloud-php 和 niucloud-java 对标项目,完善健康检查模块
- 添加 niucloud-php 对标项目用于业务逻辑参考 - 添加 niucloud-java 对标项目用于架构设计参考 - 完善 NestJS 健康检查模块 - 更新 Docker 启动脚本 - 优化模块导入配置
This commit is contained in:
0
wwjcloud-nest/docker/start-all.sh
Normal file → Executable file
0
wwjcloud-nest/docker/start-all.sh
Normal file → Executable file
@@ -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,
|
||||
|
||||
62
wwjcloud-nest/src/common/health/health.controller.ts
Normal file
62
wwjcloud-nest/src/common/health/health.controller.ts
Normal file
@@ -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(),
|
||||
};
|
||||
}
|
||||
}
|
||||
13
wwjcloud-nest/src/common/health/health.module.ts
Normal file
13
wwjcloud-nest/src/common/health/health.module.ts
Normal file
@@ -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 {}
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user