Back

CORS in Appwrite Functions - Javascript Fetch CORS Issue

  • 0
  • Web
flutterboyy
2 Dec, 2023, 05:35

Hello am trying to send a post request to my appwrite functions api server but am getting this error:

Access to fetch at 'https://[url_id].appwrite.global/' from origin 'http://localhost:3005/' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

TL;DR
The user is experiencing a CORS (Cross-Origin Resource Sharing) issue when making a post request to an Appwrite function API server. They are trying to set the 'Access-Control-Allow-Origin' header, but they are receiving a 'TypeError: res.setHeader is not a function' error. They are asking how they can send back the header to the client if they are using the Appwrite Starter function template. The error message suggests setting the request's mode to 'no-cors' if an opaque response serves their needs. Possible Solution: To fix the issue, try using the 'res.setHeader' function in the correct context and ensure that
Drake
2 Dec, 2023, 06:10

Your function will need to send back the header to allow your client.

flutterboyy
2 Dec, 2023, 06:25

and how can i send back the header to the client if am using the appwrite Starter function template

flutterboyy
2 Dec, 2023, 06:35

because am trying to set the header like this:

res.setHeader('Access-Control-Allow-Origin', '*');

and am getting this error: TypeError: res.setHeader is not a function

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