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)} }