refactor: dedupe edge api json response assembly (#1702)

* 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.
This commit is contained in:
Elie Habib
2026-03-16 11:52:56 +04:00
committed by GitHub
parent be93a940a3
commit bdd8743a26
19 changed files with 122 additions and 237 deletions

9
api/_json-response.js Normal file
View File

@@ -0,0 +1,9 @@
export function jsonResponse(body, status, headers = {}) {
return new Response(JSON.stringify(body), {
status,
headers: {
'Content-Type': 'application/json',
...headers,
},
});
}