Configuration Reference
System configuration is stored as a single JSON blob in Cloudflare KV under the key config:system. It is cached for 5 minutes. On a cache miss, defaults are used. Admins update config from the /admin/settings panel.
All configuration keys
| Key | Default | Type | Description |
|---|---|---|---|
site_name | East Grinstead Athletics Club | string | Club name — used in email templates |
site_url | https://egac.pages.dev | URL | Base URL for all links in emails |
email_from | no-reply@updates.eastgrinsteadac.co.uk | Resend sender address (must be verified) | |
venue_name | East Grinstead Leisure Centre | string | Venue name in booking confirmations |
venue_address | King Street, East Grinstead, RH19 3DJ | string | Venue address in emails |
weeks_ahead_booking | 8 | integer 1–16 | Weeks of dates shown in booking invite |
capacity_per_slot | 2 | integer 1–10 | Default per-session capacity (age group overrides this) |
academy_max_age | 10 | integer 5–16 | Upper age bound for academy routing |
admin_email | (empty) | email or empty | BCC address for admin notifications |
How configuration is read
// Read full config (cached for 5 minutes)
const config = await getConfig(env);
// Read a single value
const weeksAhead = parseInt(config.weeks_ahead_booking, 10);
// Typed helpers
const weeksAhead = getWeeksAhead(config); // → number
const capacity = getCapacityPerSlot(config); // → number
const maxAge = getAcademyMaxAge(config); // → number
All KV values are stored as strings. The typed helper functions in src/lib/config.ts handle parsing with safe fallbacks.
Validation rules
The validateConfigUpdate() function enforces these rules before saving:
| Key | Rule |
|---|---|
capacity_per_slot | Integer between 1 and 10 |
weeks_ahead_booking | Integer between 1 and 16 |
academy_max_age | Integer between 5 and 16 |
email_from | Valid email format |
site_url | Valid URL (parseable by new URL()) |
Validation errors are returned as an array of strings. The admin settings page displays them inline.
Cache behaviour
const CONFIG_CACHE_KEY = 'config:system';
const CONFIG_TTL_SECONDS = 300; // 5 minutes
// Read: KV → merge with defaults → return
// Write: merge with current → PUT to KV with TTL
// Clear: DELETE from KV (next read uses defaults until repopulated)
After saving, clearConfigCache() deletes the KV entry so the next request immediately picks up the new values rather than waiting for the TTL to expire.
Updating programmatically
import { setSystemConfig } from './src/lib/config';
await setSystemConfig({
weeks_ahead_booking: '12',
venue_name: 'New Venue Name',
}, env);
Precedence
Configuration values follow this precedence order (highest to lowest):
- KV cache (admin-set values)
CONFIG_DEFAULTSinsrc/lib/config.ts
There is no file-based config — all runtime behaviour is controlled through KV. wrangler.toml only contains non-secret environment variables (APP_ENV, EMAIL_FROM).