|
1 |
| -export const APP_CONFIG = { |
2 |
| - // supported services for API caching |
3 |
| - // each entry is a durable object that handles requests |
4 |
| - SUPPORTED_SERVICES: ['/hiro-api'], |
5 |
| - // VALUES BELOW CAN BE OVERRIDDEN BY DURABLE OBJECTS |
6 |
| - // default cache TTL used for KV |
7 |
| - CACHE_TTL: 900, // 15 minutes |
8 |
| - // default rate limiting settings |
9 |
| - MAX_REQUESTS_PER_INTERVAL: 30, // no more than 30 requests |
10 |
| - INTERVAL_MS: 15000, // in a span of 15 seconds |
11 |
| - MAX_RETRIES: 3, // max retries for failed fetches |
12 |
| - RETRY_DELAY: 1000, // multiplied by retry attempt number |
13 |
| - // how often to warm the cache, should be shorter than the cache TTL |
14 |
| - ALARM_INTERVAL_MS: 300000, // 5 minutes |
15 |
| -}; |
| 1 | +import { Env } from '../worker-configuration'; |
| 2 | + |
| 3 | +export class AppConfig { |
| 4 | + private static instance: AppConfig; |
| 5 | + private env: Env; |
| 6 | + |
| 7 | + private constructor(env: Env) { |
| 8 | + this.env = env; |
| 9 | + } |
| 10 | + |
| 11 | + public static getInstance(env?: Env): AppConfig { |
| 12 | + if (!AppConfig.instance && env) { |
| 13 | + AppConfig.instance = new AppConfig(env); |
| 14 | + } else if (!AppConfig.instance) { |
| 15 | + throw new Error('AppConfig must be initialized with environment variables first'); |
| 16 | + } |
| 17 | + return AppConfig.instance; |
| 18 | + } |
| 19 | + |
| 20 | + public getConfig() { |
| 21 | + |
| 22 | + return { |
| 23 | + // supported services for API caching |
| 24 | + // each entry is a durable object that handles requests |
| 25 | + SUPPORTED_SERVICES: ['/hiro-api', '/supabase'], |
| 26 | + // VALUES BELOW CAN BE OVERRIDDEN BY DURABLE OBJECTS |
| 27 | + // default cache TTL used for KV |
| 28 | + CACHE_TTL: 900, // 15 minutes |
| 29 | + // default rate limiting settings |
| 30 | + MAX_REQUESTS_PER_INTERVAL: 30, // no more than 30 requests |
| 31 | + INTERVAL_MS: 15000, // in a span of 15 seconds |
| 32 | + MAX_RETRIES: 3, // max retries for failed fetches |
| 33 | + RETRY_DELAY: 1000, // multiplied by retry attempt number |
| 34 | + // how often to warm the cache, should be shorter than the cache TTL |
| 35 | + ALARM_INTERVAL_MS: 300000, // 5 minutes |
| 36 | + // environment variables |
| 37 | + SUPABASE_URL: this.env.SUPABASE_URL, |
| 38 | + SUPABASE_SERVICE_KEY: this.env.SUPABASE_SERVICE_KEY, |
| 39 | + }; |
| 40 | + } |
| 41 | +} |
0 commit comments