refactor(platform-api): ♻️ Restructure health module integration in platform-api, adding registration in app.module.ts, initializing checks in main.ts, and defining routes/controllers in health.module.ts
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
f7ae693b75
commit
9ab65cc775
3 changed files with 110 additions and 0 deletions
38
@platform/codebase/@features/platform-api/src/app.module.ts
Normal file
38
@platform/codebase/@features/platform-api/src/app.module.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { APP_GUARD } from '@nestjs/core';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
import { AuthModule } from './auth/auth.module.js';
|
||||
import { QuinnSsoGuard } from './auth/quinn-sso.guard.js';
|
||||
import { CacheInvalidateModule } from './common/cache-invalidate.module.js';
|
||||
import { databaseConfig } from './config/database.config.js';
|
||||
import { HealthModule } from './health/health.module.js';
|
||||
import { AgentActionsModule } from './modules/agent-actions/agent-actions.module.js';
|
||||
import { ContentPlansModule } from './modules/content-plans/content-plans.module.js';
|
||||
import { ContentPostsModule } from './modules/content-posts/content-posts.module.js';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
cache: true,
|
||||
envFilePath: ['.env.local', '.env'],
|
||||
}),
|
||||
TypeOrmModule.forRootAsync(databaseConfig),
|
||||
CacheInvalidateModule,
|
||||
AuthModule,
|
||||
HealthModule,
|
||||
// V3 domain modules — add new modules here as they land.
|
||||
// P0 ships content-plans + content-posts + agent-actions (the verification-gate trio).
|
||||
// P1+ adds: users, orgs, personas, content-assets, engagement-events.
|
||||
ContentPlansModule,
|
||||
ContentPostsModule,
|
||||
AgentActionsModule,
|
||||
],
|
||||
providers: [
|
||||
// Global auth guard. Federates against quinn.sso (v2). Bypassed by @Public()-decorated routes.
|
||||
{ provide: APP_GUARD, useClass: QuinnSsoGuard },
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
import { Controller, Get, Module } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
import { Public } from '../auth/public.decorator.js';
|
||||
|
||||
interface HealthResponse {
|
||||
status: 'ok';
|
||||
service: 'platform.api';
|
||||
ts: string;
|
||||
}
|
||||
|
||||
@ApiTags('health')
|
||||
@Controller('health')
|
||||
class HealthController {
|
||||
@Get()
|
||||
@Public()
|
||||
check(): HealthResponse {
|
||||
return { status: 'ok', service: 'platform.api', ts: new Date().toISOString() };
|
||||
}
|
||||
}
|
||||
|
||||
@Module({
|
||||
controllers: [HealthController],
|
||||
})
|
||||
export class HealthModule {}
|
||||
47
@platform/codebase/@features/platform-api/src/main.ts
Normal file
47
@platform/codebase/@features/platform-api/src/main.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import 'reflect-metadata';
|
||||
|
||||
import { Logger, ValidationPipe } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
|
||||
import { AppModule } from './app.module.js';
|
||||
|
||||
async function bootstrap(): Promise<void> {
|
||||
const app = await NestFactory.create(AppModule, { bufferLogs: true });
|
||||
const config = app.get(ConfigService);
|
||||
const logger = new Logger('Bootstrap');
|
||||
|
||||
app.useGlobalPipes(
|
||||
new ValidationPipe({
|
||||
whitelist: true,
|
||||
forbidNonWhitelisted: true,
|
||||
transform: true,
|
||||
transformOptions: { enableImplicitConversion: false },
|
||||
}),
|
||||
);
|
||||
|
||||
app.setGlobalPrefix('api/v1', { exclude: ['health', 'health/(.*)'] });
|
||||
|
||||
if (config.get<string>('NODE_ENV') !== 'production') {
|
||||
const swaggerConfig = new DocumentBuilder()
|
||||
.setTitle('platform.api')
|
||||
.setDescription('V3 platform data plane — multi-tenant CRUD over platform.db')
|
||||
.setVersion('0.1.0')
|
||||
.addBearerAuth()
|
||||
.build();
|
||||
const document = SwaggerModule.createDocument(app, swaggerConfig);
|
||||
SwaggerModule.setup('docs', app, document);
|
||||
}
|
||||
|
||||
const port = config.get<number>('PLATFORM_API_PORT', 3060);
|
||||
await app.listen(port, '0.0.0.0');
|
||||
|
||||
logger.log(`platform.api listening on :${port} (env=${config.get('NODE_ENV') ?? 'development'})`);
|
||||
}
|
||||
|
||||
bootstrap().catch((err: unknown) => {
|
||||
const logger = new Logger('Bootstrap');
|
||||
logger.error('Fatal bootstrap error', err instanceof Error ? err.stack : String(err));
|
||||
process.exit(1);
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue