forked from xiangwang25/whale-town-end-v2
Initial WhaleTown V2 backend
This commit is contained in:
52
src/app.service.ts
Normal file
52
src/app.service.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { AppStatusResponseDto } from './business/shared';
|
||||
|
||||
/**
|
||||
* 应用服务类
|
||||
*
|
||||
* 功能描述:
|
||||
* - 提供应用基础服务
|
||||
* - 返回应用运行状态信息
|
||||
*
|
||||
* @author angjustinl
|
||||
* @version 1.0.0
|
||||
* @since 2025-12-17
|
||||
*/
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
private readonly startTime: number;
|
||||
|
||||
constructor(private readonly configService: ConfigService) {
|
||||
this.startTime = Date.now();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用状态
|
||||
*
|
||||
* @returns 应用状态信息
|
||||
*/
|
||||
getStatus(): AppStatusResponseDto {
|
||||
const isDatabaseConfigured = this.isDatabaseConfigured();
|
||||
|
||||
return {
|
||||
service: 'Pixel Game Server',
|
||||
version: '1.1.1',
|
||||
status: 'running',
|
||||
timestamp: new Date().toISOString(),
|
||||
uptime: Math.floor((Date.now() - this.startTime) / 1000),
|
||||
environment: this.configService.get<string>('NODE_ENV', 'development'),
|
||||
storageMode: isDatabaseConfigured ? 'database' : 'memory'
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查数据库配置是否完整
|
||||
*
|
||||
* @returns 是否配置了数据库
|
||||
*/
|
||||
private isDatabaseConfigured(): boolean {
|
||||
const requiredEnvVars = ['DB_HOST', 'DB_PORT', 'DB_USERNAME', 'DB_PASSWORD', 'DB_NAME'];
|
||||
return requiredEnvVars.every(varName => this.configService.get<string>(varName));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user