Back

functions cors error

  • 0
  • Cloud
stealth
28 Jan, 2025, 17:17

async function getData() { const url = "https://6798f32eae97aea2944b.appwrite.global/"; try { const response = await fetch(url); if (!response.ok) { throw new Error(Response status: ${response.status}); }

TypeScript
const json = await response.json();
console.log(json);

} catch (error) { console.error(error.message);  } }

getData();

gives me the error attached in photo

TL;DR
Developers are encountering a CORS error in their function. The solution provided involves updating the function response to include a status code and headers. Additionally, the error message attached in a photo is mentioned.
Kenny
28 Jan, 2025, 17:35

Could you try adding this to your function response

TypeScript
  return res.json({
    message: "test",
    }, 200, {
    "Access-Control-Allow-Origin": "*",
  })
Kenny
28 Jan, 2025, 17:36

make that first item whatever your actual return is, but add the status code and the last object is the headers.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more