mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-25 17:14:57 +02:00
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.
15 lines
524 B
JavaScript
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': '*',
|
|
},
|
|
});
|
|
}
|