Files
worldmonitor/api/oref-alerts.js
Elie Habib 8474092143 perf(cache): bump CDN cache TTLs for oref-alerts and youtube/live (#791)
oref-alerts: s-maxage 180s → 300s (5 min), stale-while-revalidate 60s → 120s
youtube/live: channel-based s-maxage 300s → 600s (10 min) for both relay and direct scrape paths
2026-03-02 21:29:14 +04:00

27 lines
802 B
JavaScript

import { createRelayHandler } from './_relay.js';
export const config = { runtime: 'edge' };
export default createRelayHandler({
buildRelayPath: (_req, url) => {
const endpoint = url.searchParams.get('endpoint');
return endpoint === 'history' ? '/oref/history' : '/oref/alerts';
},
forwardSearch: false,
timeout: 12000,
onlyOk: true,
cacheHeaders: () => ({
'Cache-Control': 'public, max-age=60, s-maxage=300, stale-while-revalidate=120, stale-if-error=900',
}),
fallback: (_req, corsHeaders) => new Response(JSON.stringify({
configured: false,
alerts: [],
historyCount24h: 0,
timestamp: new Date().toISOString(),
error: 'No data source available',
}), {
status: 503,
headers: { 'Content-Type': 'application/json', ...corsHeaders },
}),
});