Skip to content
Init is coming / May 19 - 23
Back

CORS Error With Appwrite Function

  • 0
  • Functions
  • Web
  • Cloud
Migs
26 Oct, 2024, 14:54

So, the function works fine with Postman and returns the expected response. However, when called from localhost or a hosted origin it doesn't return any response, even though it executes normally (I see the changes in the console).

TypeScript
Access to XMLHttpRequest at 'https://671cc505e87cdf1dff9b.appwrite.global/' from origin 'http://localhost:5173' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Tried adding CORS headers in the returned responses and nothing changed. Also tried putting a wildcard * as a hostname for my platform.

TL;DR
Developers encountering CORS error when trying to call an Appwrite function from a different origin. Function works in Postman but not from localhost or a hosted origin due to missing 'Access-Control-Allow-Origin' header. Adding CORS headers to responses and using a wildcard hostname did not resolve the issue. **Solution**: To fix the issue, developers need to add the 'Access-Control-Allow-Origin' header to the responses of the Appwrite function. This header should include the correct origin (e.g., 'http://localhost:5173') or '*' for all origins. This should allow the function to be called successfully from different origins.
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