pgnDataBase/pgnDB

CORS issue

creggian opened this issue · 4 comments

Hi, in a remote server, I have successfully installed docker images and the three containers are up and running.

Unfortunately, when I want to create an account to the website from the http://:4200 page I got a CORS error (from the Firefox debugger)

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:9095/api/user/sign-in. (Reason: CORS request did not succeed).

Basically I cannot go further the first webpage. I get the same problem even if I change the server ip (from the web interface) to 127.0.0.1:9095, localhost:9095, 0.0.0.0:9095

If I login to the running docker container and use a

curl --request POST .... http://localhost:9095/api/user/sign-in with the appropriate json content to pass parameters I am able to create a new account, as I can see it if I query the Postgresql directly.

Some useful information

  • Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-55-generic x86_64)
  • Docker Engine - Community Version: 19.03.1
  • Docker-compose version is 1.24.1 (with the 1.17 I was not even able to install all images)
  • I am using "branch release/1.0.0"

Can you help me out on that?

Thanks
Claudio

Hi,

This seems weird, because I am pretty sure this issue should already be already resolved on release/1.0.0.

I just cloned repo and started everything on my computer(Ubuntu 16.04) and it works for me just fine, so it's gonna be hard to debug it for me.

Ideas I have:

  1. Try another browser (e.g. Google Chrome)
  2. Try incognito mode (some caches problem?)
  3. Try updating Firefox (I have 66.0.3 Firefox Release April 10, 2019 and it works)
  4. Try removing all unused docker data and rebuilding everything:
  5. If nothing above works try this: https://addons.mozilla.org/pl/firefox/addon/cors-everywhere/

Please write if any of above helped and the problem was solved

Konrad

Hi Konrad, thanks for the fast reply

I totally understand that it is difficult to debug errors on someone else's machine. Let's try to do the best and we will see.

  1. Unfortunately, none of the idea worked. I have honestly the impression that the problem is not between my browser (local computer) and the frontend (remote server), but on the communication between the frontend (remote server) and the backend (remote server). Could this be possible?

  2. Do you know where I can look for logs and see if there are other errors by login to the running docker containers? The CORS error comes from the Firefox debug console

  3. I also tried another way. I ssh tunnel port 4200 locally, therefore after opening a ssh connection I can reach the frontend using http://localhost:4200, but I experience the same problem.

  4. I have Firefox 68.0.1 but I don't think this is the problem. Chrome does not work either.

  5. Additional information, in the same server there is another container running from another image and working on another port. I believe it is not part of the problem.

In attachment

  • you see the log of the build. Everything looks fine in my opinion: build.log
  • A screenshot from firefox with debugger after the problem
    Screenshot from 2019-08-12 12-42-58

Hope this helps
Claudio

Okay, I think I know what the problem is :)

As I can see you run 3 containers on remote server
Problem appears because frontend(your browser) makes requests DIRECTLY to backend. (I KNOW THIS IS SUPER POOR DESIGN)

PROBLEM SOLUTION:

What you have to do is: Go to "Change server IP" and put there:
<YOUR-REMOTE-SERVER-PATH>:9095.

How it SHOULD work

  1. Frontend should make request to <YOUR-REMOTE-SERVER-PATH>:4200/api/... (There is NGINX server there)
  2. NGINX should proxy :4200/api/... requests to backend
    e.g. in nginx.conf:
location /api {
      rewrite ^/api(.*) /$1 break;
      proxy_pass <BACKEND-IP-ADDRES>:9095;
}

where BACKEND-IP-ADDRES: https://github.com/pgnDataBase/pgnDB/blob/master/docker-compose.yml#L42

If you would like to make it better then contributing to project is very much appreciated :)

Let me know if this worked.

Konrad

Everything works perfectly now! Thanks for the help.

Thanks for the offer, I will help as much as I can. Let me first explore your project.

Best,
Claudio