refactor(guild): prefix environment variables with FABRIC_BACKEND_GUILD

This commit is contained in:
nav
2026-05-13 12:58:32 +00:00
parent 392534a6ac
commit fdb661f32b
5 changed files with 30 additions and 30 deletions

View File

@@ -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=

View File

@@ -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.

View File

@@ -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 };

View File

@@ -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',
});

View File

@@ -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}`);
}