19 lines
src/config/httpConfigClient.ts
HTTP-based ConfigClient that fetches flag state from the remote service.
// HTTP config client — fetches feature flag state from the remote config service.import type { ConfigClient } from "../middleware/featureFlag";const CONFIG_SERVICE_URL = process.env.CONFIG_SERVICE_URL ?? "http://config-service/flags";// Parameters: none — URL is read from CONFIG_SERVICE_URL env var at construction.// Returns: ConfigClient instance backed by the remote config service.export function createHttpConfigClient(): ConfigClient { return { async getFlag(name: string): Promise<boolean> { const response = await fetch(`${CONFIG_SERVICE_URL}/${name}`); if (!response.ok) { throw new Error(`Config service returned ${response.status} for flag ${name}`);}
const data = await response.json() as { enabled: boolean }; return data.enabled;},
};
}