Why am i getting CORS error from my client side when i have added Web platform from my Appwrite?
- 2
- Functions
- Web
- Cloud

I suggest cutting down code until you have a successful response. Then, slowly add code until it breaks.

Also, you probably can't send an array buffer back. It should be a string

this is my updated code and still getting CORS error trying to post request from client side
try {
const payload = querystring.parse(req.body);
const pdfBuffer = await createPdf(payload);
log(payload);
const pdfBase64 = pdfBuffer.toString('base64');
return res.send(pdfBase64, 200, { "Content-Type": "application/pdf" });
} catch (err) {
error('Error processing the request:', err);
return res.send('Internal Server Error');
}
} else {
return res.send('Bad Request');
}
};```

This is a function code?

yes, the function code

Do you have set an API key?

yes i do have

What do you get if you return (res.send) the err variable?

please, can you explain what you meant by this?

You still haven't returned the right CORS headers to tell the client they're allowed

i refactored it to this now
try {
const payload = JSON.parse(req.body);
const pdfBuffer = await createPdf(payload);
log(payload);
const pdfBase64 = pdfBuffer.toString('base64');
return res.send(pdfBase64, 200, { "Content-Type": "application/pdf" });
} catch (err) {
error('Error processing the request:', err);
return res.send('Internal Server Error');
}
} else {
log(error)
return res.send('Bad Request');
}```

still getting CORS error from the client side but it's completing/executing a successful function in my appwrite with "Bad request" response

I suggest you research more into CORS and what servers should do to allow a client to make a request

i have been doing research on the CORS and tried every solution i came across but still doesn't work, please i need help!

i had even tried to deploy on vercel thinking it could that it's browser blocking localhost but still the same thing

no...that's not how you handle CORS

The server (your function) must tell the client what origins are allowed


how can i do this because i have tried all allow origins that i know of in CORS and it's not working and i can't find anything related to handling that in the appwrite docs

i have tried all these too

Based on your research, what do you think you need to do?

that i need to handle cors and appwrite uses req
to handle headers and all but i tried what i studied i was still getting cors error

i have used the client sdk instead...thanks

how are you supposed to "handle cors"?

it would be good to learn this concept
Recommended threads
- Stuck at pinging the server to finish ad...
I'm not using the starter app and I'm not sure how to finish connecting my app to Appwrite.io. Is there a CURL command I can run to finish setup?
- 500 internal error
I get a 500 internal error when trying to access my database on appwrite cloud. Sometimes it would start working but this time it never corrects.
- Error getting session: AppwriteException...
I get this error `Error getting session: AppwriteException: User (role: guests) missing scope (account)` when running in prod. As soon as I try running my app o...
