Back

Acces-Control-Allow-Origin Error

  • 0
  • Web
  • Databases
  • Storage
  • Cloud
  • Self Hosted
Ankittttt
17 May, 2024, 07:34

Access to XMLHttpRequest at 'https://cloud.appwrite.io/v1/databases/66387c50002eb78ca32f/collections/66387c5d003a16f1ed53/documents?queries%5B0%5D=orderDesc%28%22%24createdAt%22%29' from origin 'https://todo-list-vert-omega-47.vercel.app' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header has a value 'https://localhost' that is not equal to the supplied origin. I'm getting this error , It working with localhost correctly but i'm want to use with vercel , deployed on vercel with correct URL and project_id , but Idk why its occuring can anyone fix this ?

TL;DR
Developers are facing an Access-Control-Allow-Origin error when trying to use an Appwrite API endpoint deployed on Vercel. The error is related to the 'Access-Control-Allow-Origin' header value not matching the supplied origin. To resolve this, the developers need to ensure that the CORS policy on the API server allows requests from the Vercel deployment URL by configuring the header to have the correct origin value.
Ankittttt
17 May, 2024, 07:44

This

Ankittttt
17 May, 2024, 07:45
TypeScript

export const AppwriteURL =
  import.meta.env.VITE_APPWRITE_URL || "https://cloud.appwrite.io/v1";

export const PORJECT_ID =
  import.meta.env.VITE_APPWRITE_DATABASES_ID || "66387c2d00392835a51c";

export const DATABASES_ID =
  import.meta.env.VITE_APPWRITE_DATABASES_ID || "66387c50002eb78ca32f";

export const COLLECTION_MESSAGE_ID =
  import.meta.env.VITE_APPWRITE_COLLECTION_MESSAGE_ID || "66387c5d003a16f1ed53";

export const client = new Client();
client.setEndpoint(AppwriteURL).setProject(PORJECT_ID);

export const databases = new Databases(client);
``` aapwriteConfig.js file
Ankittttt
17 May, 2024, 07:46
Ankittttt
17 May, 2024, 07:47
TypeScript
VITE_APPWRITE_URL = "https://cloud.appwrite.io/v1"

VITE_APPWRITE_DATABASES_ID  ='66387c50002eb78ca32f'
VITE_APPWRITE_COLLECTION_MESSAGE_ID  ='66387c5d003a16f1ed53'```
Ankittttt
17 May, 2024, 07:47

env file

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