Back

Access to XMLHttpRequest at 'https://cloud.appwrite.io/v1/databases' has been blocked by CORS policy

  • 1
  • Databases
  • Web
oyeins.dev
21 Feb, 2024, 23:02

Method PATCH is not allowed by Access-Control-Allow-Methods in preflight response.

TypeScript
const likeProposal = async () => {
      const response = await databases.updateDocument(databaseId, proposalCollection, proposal.$id, {
         ...proposal,
         likes: Number(proposal.likes) + 1,
      })

      console.log(response)
}
TL;DR
Developers are encountering a CORS policy issue in their application related to Appwrite requests. The error occurs specifically in Chrome due to a browser extension. The issue is also related to the PATCH method not being allowed, causing a Network request failed error in the code when trying to update a document. A potential solution is to watch a video on common CORS errors or consider adjusting permissions and the hostname setup.
Evdog
21 Feb, 2024, 23:15

This vid goes through a few of the common CORS errors that a lot of our devs see, give it a shot here: https://www.youtube.com/watch?v=oEpRh9H5l5g

oyeins.dev
21 Feb, 2024, 23:37

Same error

D5
21 Feb, 2024, 23:37

What's all the code?

oyeins.dev
21 Feb, 2024, 23:37

I've also change the hostname in my console to be a wildcard but I'm still getting the same error

D5
21 Feb, 2024, 23:38

Is this cloud or self-hosted?

oyeins.dev
21 Feb, 2024, 23:39

error or my actual code?

oyeins.dev
21 Feb, 2024, 23:39

cloud

D5
21 Feb, 2024, 23:42

Both

D5
21 Feb, 2024, 23:42

All the code related to appwrite and all the errors

oyeins.dev
21 Feb, 2024, 23:47
TypeScript
Access to XMLHttpRequest at 'https://cloud.appwrite.io/v1/databases' has been blocked by CORS policy

Method PATCH is not allowed by Access-Control-Allow-Methods in preflight response.

Uncaught (in promise) AppwriteException: Network request failed
oyeins.dev
21 Feb, 2024, 23:47
TypeScript
const likeProposal = async () => {
      const response = await databases.updateDocument(databaseId, proposalCollection, proposal.$id, {
         ...proposal,
         likes: Number(proposal.likes) + 1,
      })

      console.log(response)
}
oyeins.dev
21 Feb, 2024, 23:48

this is the only code related to appwrite that is failing

D5
21 Feb, 2024, 23:49

So everything works except that?

oyeins.dev
21 Feb, 2024, 23:49

yes

D5
21 Feb, 2024, 23:49

Do you have some relationships?

oyeins.dev
21 Feb, 2024, 23:49

no

D5
21 Feb, 2024, 23:51

And do you have set edit permissions?

oyeins.dev
21 Feb, 2024, 23:52

yes, i have permission to create, read, update and delete set to any in my console

oyeins.dev
21 Feb, 2024, 23:52

i got this when i hovered over the updateDocument function in vscode

TypeScript
Update document

Update a document by its unique ID. Using the patch method you can pass only specific fields that will get updated.

@throws — {AppwriteException}

what's the patch method?

D5
21 Feb, 2024, 23:58

I think the doc ID is not correct or some of the data in the payload. Maybe ..proposal sin't correct?

oyeins.dev
22 Feb, 2024, 00:32

I just ran my application with firefox and it worked perfectly, but it's not working in chrome

oyeins.dev
22 Feb, 2024, 00:36

Thanks @Evdog and @D5 the error was caused by an extension I installed in chrome

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