mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-25 17:14:57 +02:00
DRY 7 edge functions that duplicated relay proxy boilerplate (~80% identical: CORS, origin check, OPTIONS, relay URL construction, auth headers, fetchWithTimeout, error handling). - New `api/_relay.js` exports createRelayHandler factory + getRelayBaseUrl, getRelayHeaders, fetchWithTimeout utilities - Convert ais-snapshot, polymarket, opensky, oref-alerts, telegram-feed to ~15-25 line config objects via createRelayHandler - Refactor youtube/live.js and rss-proxy.js to import shared utils only (complex handlers not suited for factory pattern) - 30 unit/behavior tests in tests/relay-helper.test.mjs Net: -501 lines removed, +72 added across 7 prod files. Relay utility functions exist in 1 place instead of 7.
17 lines
564 B
JavaScript
17 lines
564 B
JavaScript
import { createRelayHandler } from './_relay.js';
|
|
|
|
export const config = { runtime: 'edge' };
|
|
|
|
export default createRelayHandler({
|
|
relayPath: '/polymarket',
|
|
timeout: 15000,
|
|
requireApiKey: true,
|
|
requireRateLimit: true,
|
|
cacheHeaders: (ok) => ({
|
|
'Cache-Control': ok
|
|
? 'public, max-age=120, s-maxage=300, stale-while-revalidate=900, stale-if-error=1800'
|
|
: 'public, max-age=10, s-maxage=30, stale-while-revalidate=120',
|
|
...(ok && { 'CDN-Cache-Control': 'public, s-maxage=300, stale-while-revalidate=900, stale-if-error=1800' }),
|
|
}),
|
|
});
|