feat: 初始化项目

This commit is contained in:
R524809
2026-10-12 15:22:27 +08:00
commit 3c6fd2c8ca
37 changed files with 4859 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { HealthController } from './health/health.controller';
@Module({
controllers: [HealthController],
})
export class AppModule {}
+6
View File
@@ -0,0 +1,6 @@
import type { INestApplication } from '@nestjs/common';
export function configureApplication(app: INestApplication): void {
app.setGlobalPrefix('api/v1');
app.enableShutdownHooks();
}
+27
View File
@@ -0,0 +1,27 @@
export interface RuntimeOptions {
host: string;
port: number;
}
export function getRuntimeOptions(
env: NodeJS.ProcessEnv = process.env,
): RuntimeOptions {
const rawPort = env.PORT ?? '3000';
const port = Number(rawPort);
const host = (env.HOST ?? '127.0.0.1').trim();
if (
!/^\d+$/.test(rawPort) ||
!Number.isInteger(port) ||
port < 1 ||
port > 65535
) {
throw new Error('PORT must be an integer between 1 and 65535');
}
if (!host) {
throw new Error('HOST must not be empty');
}
return { host, port };
}
@@ -0,0 +1,17 @@
import { Controller, Get } from '@nestjs/common';
import type { ApiSuccess, HealthStatus } from '@doodle/contracts';
@Controller('health')
export class HealthController {
@Get()
getHealth(): ApiSuccess<HealthStatus> {
return {
code: 0,
message: 'ok',
data: {
status: 'ok',
service: 'doodle-store-server',
},
};
}
}
+31
View File
@@ -0,0 +1,31 @@
import 'reflect-metadata';
import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { configureApplication } from './app.setup';
import { getRuntimeOptions } from './common/runtime-options';
async function bootstrap(): Promise<void> {
try {
process.loadEnvFile();
} catch (error) {
if (!(
error instanceof Error &&
'code' in error &&
error.code === 'ENOENT'
)) {
throw error;
}
}
const { port, host } = getRuntimeOptions();
const app = await NestFactory.create(AppModule);
configureApplication(app);
await app.listen(port, host);
Logger.log(`Listening on http://${host}:${port}/api/v1/health`, 'Bootstrap');
}
void bootstrap().catch((error: unknown) => {
Logger.error(error, undefined, 'Bootstrap');
process.exit(1);
});
+5
View File
@@ -0,0 +1,5 @@
# 业务模块预留目录
后续按迁移方案逐步加入 auth、users、worksheets、categories、favorites、downloads、content、assets 和 legacy 模块。
当前没有创建任何业务 Controller、Service、数据库模型或伪接口。健康检查独立放在 `src/health`,不代表业务迁移已完成。