mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-25 17:14:57 +02:00
* refactor: dedupe edge api json response assembly * refactor: expand jsonResponse helper to all edge functions Roll out jsonResponse() from _json-response.js to 16 files (14 handlers + 2 shared helpers), eliminating 55 instances of the new Response(JSON.stringify(...)) boilerplate. Only exception: health.js uses JSON.stringify(body, null, indent) for pretty-print mode, which is incompatible with the helper signature. Replaced local jsonResponse/json() definitions in contact.js, register-interest.js, and cache-purge.js with the shared import.
13 lines
481 B
JavaScript
13 lines
481 B
JavaScript
import { jsonResponse } from './_json-response.js';
|
|
|
|
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 jsonResponse({ country }, 200, {
|
|
'Cache-Control': 'public, max-age=300, s-maxage=3600, stale-if-error=3600',
|
|
'Access-Control-Allow-Origin': '*',
|
|
});
|
|
}
|