Back

[SOLVED] Error when logging to console after account created in Chrome

  • 0
  • Self Hosted
  • Accounts
Rafael Hengles
20 Feb, 2023, 18:54

But then the base app would be unsecured

TL;DR
The user is experiencing CORS errors when making API calls to the Appwrite console from their frontend app. The server is responding with an incorrect 'Access-Control-Allow-Origin' header. The user resolves the issue by obtaining the correct IP address for NPM and making sure that Traefik and NPM are in the same Docker network. They also mention setting up Nginx Proxy Manager (NPM) in front of Appwrite to handle certificates. A link to a Medium article on running Appwrite behind Nginx is provided. The issue is marked as solved.
Rafael Hengles
20 Feb, 2023, 18:55

Or would that be solved by NPM (Nginx Proxy Manager) ?

Drake
20 Feb, 2023, 18:56

are you saying your front end app is not connecting to console.whatever?

Drake
20 Feb, 2023, 18:56

do you also have NPM in front of appwrite?

Rafael Hengles
20 Feb, 2023, 18:58

Well, I'm kind of cheating, because I also redirecting myapp.mydomain.tld/v1/ to be served by the appwrite service in the traefik config. Because I don't have yet an certificate for console., the app would not work without this

Rafael Hengles
20 Feb, 2023, 18:58

Not yet, but I'm planning on adding it

Drake
20 Feb, 2023, 19:00

👀 this doesn't really sound right...

Drake
20 Feb, 2023, 19:00

probably best to set this up first especially if you're already hosting multiple apps on the same server. and if you're using NPM, Appwrite's certificates wouldn't really matter

Rafael Hengles
20 Feb, 2023, 19:01

Great, I'll set it up then

Drake
20 Feb, 2023, 19:03

_APP_DOMAIN should be your main domain (like console.whatever). For project specific endpoints, you can use custom domains (https://appwrite.io/docs/custom-domains). But, like I said, if you're using NPM, you may not need to add a custom domain since NPM would handle the certificate generation.

For using NPM in front of Appwrite, you can refer to this: https://medium.com/@stnguyen90/how-to-run-appwrite-behind-nginx-19348ed34243

Rafael Hengles
20 Feb, 2023, 19:09

Awesome! Thanks a lot!! 💯 👏

Rafael Hengles
20 Feb, 2023, 19:33

I didn't understand this from the article:

<IP Address of NPM> How do I get this IP, if it's running on the same server ?
Rafael Hengles
20 Feb, 2023, 19:34

Is it 127.0.0.1, even though it's inside of docker ?

Drake
20 Feb, 2023, 19:37

not 127.0.0.1

Rafael Hengles
20 Feb, 2023, 19:37

is the public IP of the server ?

Drake
20 Feb, 2023, 19:38

so traefik and NPM should be in the same docker network and have an IP address in that network. You can run docker inspect <network> to get the containers in the network

Rafael Hengles
20 Feb, 2023, 19:38

Good, I'll try that

Rafael Hengles
20 Feb, 2023, 19:43

Is it (1) IPAM.Config[0].Gateway or (2) Containers.{ID}.IPv4Address ? Option (2) has a "/16" subnet mask after the address, does it work with that ?

Drake
20 Feb, 2023, 19:44

it would be the IPv4 Address without the subnet mask

Rafael Hengles
20 Feb, 2023, 19:44

Got it

Rafael Hengles
20 Feb, 2023, 21:45

I got the domains working with https in NPM, in the console everything works. But when the frontend app calls the console endpoints, there are some cors errors. The frontend calls this:

TypeScript
GET https://console.myapp.mydomain.tld/v1/account

origin: https://myapp.mydomain.tld
referer: https://myapp.mydomain.tld/

In the devtools logs:

TypeScript
Access to XMLHttpRequest at 'https://console.myapp.mydomain.tld/v1/account' from origin 'https://myapp.mydomain.tld' 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.

It's very strange because before the GET /v1/account, the browser sends an OPTIONS /v1/account, and on the Options method the server replies with the right access-control-allow-origin: https://myapp.mydomain.tld.

But when the browser calls the Get method, for some reason the server replies with access-control-allow-origin: https://localhost, which I don't understand why. It doesn't appear to be related to NPM because it works in the Option method, but I dunno.

Drake
20 Feb, 2023, 22:05

Did you add the hostname for your app as a web platform for your project in the Appwrite console?

Rafael Hengles
20 Feb, 2023, 22:09

Maybe not, I'll see

Rafael Hengles
21 Feb, 2023, 11:18

Yes, that solved it! Thanks again 👍

Drake
21 Feb, 2023, 15:02

[SOLVED] Error when logging to console after account created 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