Files
worldmonitor/api/geo.js
Elie Habib 1edf8347bd fix(runtime): route all /api/* calls through CDN edge instead of direct Vercel (#780)
installWebApiRedirect() existed but was dead in production — VITE_WS_API_URL
was never set on Vercel, and even if enabled, only 4 path patterns were
whitelisted while /api/bootstrap (called every page load) and many others
were excluded.

Changes:
- Replace allowlist regex array with catch-all startsWith('/api/')
- Add 502/503 to CDN fallback so edge outages degrade to direct Vercel
- geo.js: prefer Cloudflare cf-ipcountry header (works through CDN),
  filter Tor exit nodes (T1), fall back to x-vercel-ip-country

Requires setting VITE_WS_API_URL=https://api.worldmonitor.app in Vercel
env vars and redeploying to activate.
2026-03-02 19:04:07 +04:00

15 lines
524 B
JavaScript

export const config = { runtime: 'edge' };
export default function handler(req) {
const cfCountry = req.headers.get('cf-ipcountry');
const country = (cfCountry && cfCountry !== 'T1' ? cfCountry : null) || req.headers.get('x-vercel-ip-country') || 'XX';
return new Response(JSON.stringify({ country }), {
status: 200,
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'public, max-age=300, s-maxage=3600, stale-if-error=3600',
'Access-Control-Allow-Origin': '*',
},
});
}