From 6b326a5a7bfa882c05cc84cc5affb97459b2f0f9 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Thu, 2 Oct 2025 12:43:41 -0700 Subject: [PATCH] Fix: Add CORS headers to post detail API --- functions/api/posts/[id].js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/functions/api/posts/[id].js b/functions/api/posts/[id].js index 5288855..777ce36 100644 --- a/functions/api/posts/[id].js +++ b/functions/api/posts/[id].js @@ -1,4 +1,4 @@ -const json=(d,o={})=>{const h=new Headers(o.headers);h.set('Content-Type','application/json');return new Response(JSON.stringify(d),{...o,headers:h})}; +const json=(d,o={},req)=>{const h=new Headers(o.headers);h.set('Content-Type','application/json');const origin=req?.headers.get('Origin');if(origin?.endsWith('.speech.capital')){h.set('Access-Control-Allow-Origin',origin);h.set('Access-Control-Allow-Credentials','true')}return new Response(JSON.stringify(d),{...o,headers:h})}; const cookie=c=>(c.match(/auth_user=([^;]+)/)?.[1]||null); const hash=c=>(c.match(/auth_hash=([^;]+)/)?.[1]||null); const tsEq=(a,b)=>{if(!a||!b)return!1;let d=a.length^b.length;for(let i=0;i{c.replies=[];map[c.id]=c;if(!c.parent_id)tree.push(c);else if(map[c.parent_id])map[c.parent_id].replies.push(c)}); - return json({post,comments:tree}); - }catch(e){return json({error:{message:e.message}},{status:500})} + return json({post,comments:tree},{},request); + }catch(e){return json({error:{message:e.message}},{status:500},request)} }