Back

How do I fix this CORS issue when AppWrite and my application are on different servers?

  • 0
  • Self Hosted
  • Web
Rich
15 Aug, 2023, 13:18

When I visit my appliation via 165.232.32.238:3000 and I try and login I get this:

Access to XMLHttpRequest at 'http://167.99.207.160/v1/account/sessions/email' from origin 'http://165.232.32.238:3000' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header has a value 'http://localhost:3000' that is not equal to the supplied origin. login-7c5fe77fbaa93a15.js:1 Network request failed _app-b34275639937d04b.js:1 POST http://167.99.207.160/v1/account/sessions/email net::ERR_FAILED 403 (Forbidden)

I don't understand why it is saying localhost?

Also, when I go into my AppWrite instance which is on 167.99.207.160 and I try and add a custom domain I get "unreachable CNAME target (localhost). Please check the _APP_DOMAIN_TARGET environment variable of your AppWrite server.

I asked ChatGPT to see if it could help and it suggested:

  1. Fixing the CORS Issue: You need to configure AppWrite to allow requests from http://165.232.32.238:3000 (and later from http://www.growthpathways.co.uk once your domain is set up).

Update Allowed Origins:

Go to the AppWrite Dashboard > Settings and add http://165.232.32.238:3000 to the list of allowed origins.

But there is no list of allowed origins, only the custom domain, which results in the error message above.

Is there an env I need to edit or something?

TL;DR
The user is experiencing a CORS issue between their AppWrite instance and their application on different servers. They are seeing an error message mentioning 'localhost' when trying to login. Additionally, they are unable to add a custom domain in AppWrite due to an "unreachable CNAME target (localhost)" error. Solution: To fix the CORS issue, they should configure AppWrite to allow requests from their application's origin. They can do this by adding the application's URL (e.g., http://165.232.32.238:3000) to the list of allowed origins in the AppWrite Dashboard settings. If they cannot find
Binyamin
15 Aug, 2023, 13:19

In your project overview page add platform Web

Binyamin
15 Aug, 2023, 13:20

Inside that you can add your server IP / domain

Binyamin
15 Aug, 2023, 13:20

You can add as many as needed

Rich
15 Aug, 2023, 13:21

Where is the setting?

I have my platform added as a web platform:

Binyamin
15 Aug, 2023, 13:22

You've added the as 165.232.32.238 Web app?

Rich
15 Aug, 2023, 13:23

Ah I must have had it set up as localhost, as I've only now deployed to live

Rich
15 Aug, 2023, 13:23

can I change it or am I going to have to reset up all the databases?

Binyamin
15 Aug, 2023, 13:23

Yes it's changeable

Binyamin
15 Aug, 2023, 13:24

And, you can add, delete and edit

Rich
15 Aug, 2023, 13:25

Excellent - thank you for you swift help - very much appreciated!!

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