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
- Update User Error
```ts const { users, databases } = await createAdminClient(); const session = await getLoggedInUser(); const user = await users.get(session.$id); if (!use...
- apple exchange code to token
hello guys, im new here π I have created a project and enabled apple oauth, filled all data (client id, key id, p8 file itself etc). I generate oauth code form...
- Our Appwrite organization is suspended
Please give support regarding this , no app is working now , please solve my issue and give support , no one is replying in message section or email.