From 4c6ce43e59056aee6a51ba821c9d0d8d2f03af1f Mon Sep 17 00:00:00 2001 From: Alex Pooley Date: Thu, 20 Mar 2025 01:37:37 +0000 Subject: better response handling + cors --- source/index.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'source/index.js') diff --git a/source/index.js b/source/index.js index 616c237..9d4a9e2 100644 --- a/source/index.js +++ b/source/index.js @@ -5,7 +5,7 @@ export default { switch (url.pathname) { // return a simple hello world message case "/": - return Response.json({ + return Respond({ message: "Hello, World! :3", }); @@ -33,19 +33,28 @@ export default { ]; if (acceptedServices.includes(service)) - return Response.json({ + return Respond({ status: "ok", }); - return Response.json({ + return Respond({ error: `service not found`, }); // default case default: - return Response.json({ + return Respond({ error: "not found", }); } }, }; + +function Respond(body) { + return new Response(JSON.stringify(body), { + headers: { + "Access-Control-Allow-Origin": "*", + "Content-Type": "application/json", + }, + }); +} -- cgit v1.2.3