mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-26 01:24:59 +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.
16 lines
438 B
JavaScript
16 lines
438 B
JavaScript
import { createRelayHandler } from './_relay.js';
|
|
|
|
export const config = { runtime: 'edge' };
|
|
|
|
export default createRelayHandler({
|
|
relayPath: '/opensky',
|
|
timeout: 20000,
|
|
cacheHeaders: () => ({
|
|
'Cache-Control': 'public, s-maxage=120, stale-while-revalidate=60, stale-if-error=300',
|
|
}),
|
|
extraHeaders: (response) => {
|
|
const xCache = response.headers.get('x-cache');
|
|
return xCache ? { 'X-Cache': xCache } : {};
|
|
},
|
|
});
|