I suggest cutting down code until you have a successful response. Then, slowly add code until it breaks.
Why am i getting CORS error from my client side when i have added Web platform from my Appwrite?
Votes
2
Replies
24
Participants
Unknown
Messages
25
Also, you probably can't send an array buffer back. It should be a string
Rank 2: Process
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?
Rank 2: Process
yes, the function code
Do you have set an API key?
Rank 2: Process
yes i do have
What do you get if you return (res.send) the err variable?
Rank 2: Process
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
Rank 2: Process
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'); }```Rank 2: Process
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
Rank 2: Process
i have been doing research on the CORS and tried every solution i came across but still doesn't work, please i need help!
Rank 2: Process
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
Rank 2: Process
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
Rank 2: Process
i have tried all these too
Based on your research, what do you think you need to do?
Rank 2: Process
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
Rank 2: Process
i have used the client sdk instead...thanks
how are you supposed to "handle cors"?
it would be good to learn this concept