diff --git a/.env.example b/.env.example index 0ae91ba..8847745 100644 --- a/.env.example +++ b/.env.example @@ -1,20 +1,20 @@ # Server -PORT=7002 +FABRIC_BACKEND_GUILD_PORT=7002 # MySQL -DB_HOST=mysql-guild -DB_PORT=3306 -DB_USER=fabric -DB_PASSWORD=fabric -DB_NAME=fabric_guild -DB_SYNC=true -DB_LOGGING=false +FABRIC_BACKEND_GUILD_DB_HOST=mysql-guild +FABRIC_BACKEND_GUILD_DB_PORT=3306 +FABRIC_BACKEND_GUILD_DB_USER=fabric +FABRIC_BACKEND_GUILD_DB_PASSWORD=fabric +FABRIC_BACKEND_GUILD_DB_NAME=fabric_guild +FABRIC_BACKEND_GUILD_DB_SYNC=true +FABRIC_BACKEND_GUILD_DB_LOGGING=false # Guild identity -GUILD_NODE_ID=guild-node-1 -GUILD_NODE_NAME=Guild Node 1 -GUILD_PUBLIC_ENDPOINT=http://localhost:7002 +FABRIC_BACKEND_GUILD_NODE_ID=guild-node-1 +FABRIC_BACKEND_GUILD_NODE_NAME=Guild Node 1 +FABRIC_BACKEND_GUILD_PUBLIC_ENDPOINT=http://localhost:7002 # Center handshake -CENTER_BASE_URL=http://backend-center:7001 -CENTER_API_KEY= +FABRIC_BACKEND_GUILD_CENTER_BASE_URL=http://backend-center:7001 +FABRIC_BACKEND_GUILD_CENTER_API_KEY= diff --git a/README.md b/README.md index 7f247b3..05c704e 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ Guild Node service for Fabric. - Seq allocator and range query endpoints ## Required env (startup hard checks) -- `CENTER_BASE_URL` -- `CENTER_API_KEY` -- `GUILD_NODE_ID` +- `FABRIC_BACKEND_GUILD_CENTER_BASE_URL` +- `FABRIC_BACKEND_GUILD_CENTER_API_KEY` +- `FABRIC_BACKEND_GUILD_NODE_ID` If any of the above is missing, service startup fails immediately. diff --git a/src/common/center-auth.ts b/src/common/center-auth.ts index 39e530b..c1b7a1f 100644 --- a/src/common/center-auth.ts +++ b/src/common/center-auth.ts @@ -1,7 +1,7 @@ export async function introspectGuildToken(token: string): Promise<{ active: boolean; user?: { id: string; email?: string } }> { - const centerBaseUrl = process.env.CENTER_BASE_URL; - const guildNodeId = process.env.GUILD_NODE_ID; - const centerApiKey = process.env.CENTER_API_KEY; + const centerBaseUrl = process.env.FABRIC_BACKEND_GUILD_CENTER_BASE_URL; + const guildNodeId = process.env.FABRIC_BACKEND_GUILD_NODE_ID; + const centerApiKey = process.env.FABRIC_BACKEND_GUILD_CENTER_API_KEY; if (!centerBaseUrl || !guildNodeId || !centerApiKey) { return { active: false }; diff --git a/src/database.config.ts b/src/database.config.ts index 966c31e..5dccfb5 100644 --- a/src/database.config.ts +++ b/src/database.config.ts @@ -11,11 +11,11 @@ import { IdempotencyRecord } from './entities/idempotency-record.entity'; export const buildTypeOrmConfig = (): TypeOrmModuleOptions => ({ type: 'mysql', - host: process.env.DB_HOST ?? 'mysql-guild', - port: Number(process.env.DB_PORT ?? 3306), - username: process.env.DB_USER ?? 'fabric', - password: process.env.DB_PASSWORD ?? 'fabric', - database: process.env.DB_NAME ?? 'fabric_guild', + host: process.env.FABRIC_BACKEND_GUILD_DB_HOST ?? 'mysql-guild', + port: Number(process.env.FABRIC_BACKEND_GUILD_DB_PORT ?? 3306), + username: process.env.FABRIC_BACKEND_GUILD_DB_USER ?? 'fabric', + password: process.env.FABRIC_BACKEND_GUILD_DB_PASSWORD ?? 'fabric', + database: process.env.FABRIC_BACKEND_GUILD_DB_NAME ?? 'fabric_guild', entities: [ Guild, Channel, @@ -27,6 +27,6 @@ export const buildTypeOrmConfig = (): TypeOrmModuleOptions => ({ GuildMemberRole, IdempotencyRecord, ], - synchronize: (process.env.DB_SYNC ?? 'true') === 'true', - logging: (process.env.DB_LOGGING ?? 'false') === 'true', + synchronize: (process.env.FABRIC_BACKEND_GUILD_DB_SYNC ?? 'true') === 'true', + logging: (process.env.FABRIC_BACKEND_GUILD_DB_LOGGING ?? 'false') === 'true', }); diff --git a/src/main.ts b/src/main.ts index 273f5c8..e58fe90 100644 --- a/src/main.ts +++ b/src/main.ts @@ -15,9 +15,9 @@ function requireEnv(name: string): string { } function validateEnv(): void { - requireEnv('CENTER_BASE_URL'); - requireEnv('CENTER_API_KEY'); - requireEnv('GUILD_NODE_ID'); + requireEnv('FABRIC_BACKEND_GUILD_CENTER_BASE_URL'); + requireEnv('FABRIC_BACKEND_GUILD_CENTER_API_KEY'); + requireEnv('FABRIC_BACKEND_GUILD_NODE_ID'); } async function bootstrap() { @@ -43,7 +43,7 @@ async function bootstrap() { const swaggerDoc = SwaggerModule.createDocument(app, swaggerConfig); SwaggerModule.setup('docs', app, swaggerDoc); - const port = process.env.PORT ? Number(process.env.PORT) : 7002; + const port = process.env.FABRIC_BACKEND_GUILD_PORT ? Number(process.env.FABRIC_BACKEND_GUILD_PORT) : 7002; await app.listen(port); console.log(`Fabric.Backend.Guild listening on :${port}`); }