Back

after trying to execute function using fetch my project got blocked!

  • 0
  • Web
Rameez Root
29 Jan, 2025, 09:23

is there a speicifc way to execute ,request a function?

TL;DR
Function to be triggered via fetch is blocked after resolving CORS issue. Developer shared code snippet with preflight request handling for CORS. Project not blocked, likely CORS misconfiguration. Solution: ensure proper CORS headers set in function response, particularly 'Access-Control-Allow-Origin'.
D5
29 Jan, 2025, 09:40

The project doesn't seems to be blocked, I think?

D5
29 Jan, 2025, 09:40

Just CORS not set

Rameez Root
29 Jan, 2025, 09:43

i resolveed the cors issue now its block, here is the code of function:

// This Appwrite function will be executed every time your function is triggered export default async ({ req, res, log, error }) => {

// Handle preflight (OPTIONS) requests for CORS

if (req.method === 'OPTIONS') {

TypeScript
return res.send('', 204, {

  'Access-Control-Allow-Origin': '*',

  'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',

  'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Appwrite-Key'

});

}

return res.json({ motto: "HELLO CORS!" }, 200, { "Access-Control-Allow-Origin": "*", }); };

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