feat(guild): fail fast when center auth env is missing

This commit is contained in:
nav
2026-05-13 08:52:16 +00:00
parent db85e69ef3
commit 392534a6ac
2 changed files with 23 additions and 0 deletions

View File

@@ -13,3 +13,10 @@ Guild Node service for Fabric.
- API skeleton (NestJS) - API skeleton (NestJS)
- Chat domain models - Chat domain models
- Seq allocator and range query endpoints - Seq allocator and range query endpoints
## Required env (startup hard checks)
- `CENTER_BASE_URL`
- `CENTER_API_KEY`
- `GUILD_NODE_ID`
If any of the above is missing, service startup fails immediately.

View File

@@ -6,7 +6,23 @@ import { AppModule } from './app.module';
import { createRequestContextMiddleware } from './common/request-context.middleware'; import { createRequestContextMiddleware } from './common/request-context.middleware';
import { MetricsService } from './common/metrics.service'; import { MetricsService } from './common/metrics.service';
function requireEnv(name: string): string {
const value = process.env[name];
if (!value || value.trim() === '') {
throw new Error(`Missing required env: ${name}`);
}
return value;
}
function validateEnv(): void {
requireEnv('CENTER_BASE_URL');
requireEnv('CENTER_API_KEY');
requireEnv('GUILD_NODE_ID');
}
async function bootstrap() { async function bootstrap() {
validateEnv();
const app = await NestFactory.create(AppModule); const app = await NestFactory.create(AppModule);
app.setGlobalPrefix('api'); app.setGlobalPrefix('api');
const metrics = app.get(MetricsService); const metrics = app.get(MetricsService);