epam / Indigo

Universal cheminformatics toolkit, utilities and database search tools
http://lifescience.opensource.epam.com
Apache License 2.0
291 stars 100 forks source link

indigo-service CORS #214

Open Doidel opened 3 years ago

Doidel commented 3 years ago

I've installed the docker image of the indigo service and it's up and running. Directly calling the API works fine, however now I get CORS erros. An example:

Access to fetch at 'http://localhost:50738/info' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

The /info url is the first thing Ketcher calls to determine whether the indigo-service is up and running. So I searched around and found the nginx conf you're using where you actually enable CORS.

Now I'm at my wit's end and I'll have to dig deep to understand why the nginx CORS header doesn't apply here. But before I do that, I thought maybe you already know and I'm just missing something. Do you have an idea what the issue could be? No worries if you don't, then I'll just spend some time researching and I'll eventually post the solution here.

Thanks!

AlexanderSavelyev commented 3 years ago

the nginx file which you pointed is not used inside the docker instance. please inform how do you run http://localhost:50738 and http://localhost:4200? it seems there are some missing configuration for http://localhost:50738

Doidel commented 3 years ago

Hi @AlexanderSavelyev and thanks for the response!

I ran this docker image with the following command:

docker run --rm -p 50738:80 epmlsop/indigo_service python3 app.py -s 0.0.0.0 -p 80

Well, the port 50738 is one I chose randomly, and on localhost:4200 is where Ketcher is integrated (an Angular app).

I don't understand the explanation why nginx is required. If I was just able to edit the CORS headers in the docker image of your service container I could easily use the service. E.g. if the docker image runs its pythong/uwsgi combo on nginx, I'd just add a CORS header there and I'm set. So I guess my question is: Where can I find the web server within the docker image so I can add the CORS headers?

AlexanderSavelyev commented 3 years ago

Hi @Doidel

There is no nginx inside epmlsop/indigo_service

One can use nginx (or any other http server with uwsgi support, e.g. apache) to route the traffic for an application correctly without using Allow-Origin' '' headers (use is not secure)

It is suggested that Ketcher is integrated into some web application which already contains http server

If you want to use web server within a docker image, please take a look at https://github.com/epam/ketcher/issues/1

There is a docker-compose example with nginx service The only advice is to use host network and also you will need to re-route the 4200 port to 80. There are many instructions of how it can be done

Please use 'command: supervisord -n' instead of 'python3 app.py' to be able restart service on a fail.

docker run --restart=always -d -p 8002:8002 -e "INDIGO_UWSGI_RUN_PARAMETERS=--plugin python3 --py-autoreload=1" -e "PYTHONPATH=/srv/indigo-python" -e "PYTHONDONTWRITEBYTECODE=1" --name=indigo_service epmlsop/indigo_service:latest /bin/sh -c "supervisord -n"

Thanks Aleksandr

Doidel commented 3 years ago

Again thanks for your reply @AlexanderSavelyev

I understand what you want me to do. I just thought it isn't necessary and an overkill, because I just want to add one header to the HTTP responses, that's all. However, after reading up on uWSGI and particularly this documentation I understand now why this isn't the way it's done. Without the preexisting knowledge of uWSGI and how this hosting is supposed to work, I think the information on the indigo service documentation page is not clear enough. I didn't understand from this page that I needed to proxy the docker web service through another web server outside the container.

Thank you for the updated command. I'll try out both the command and the web server proxy, and close the issue when both of it works.

Doidel commented 3 years ago

@mkviatkovskii I got back to this discussion and tried to run your docker command, which unfortunately doesn't work for me. I then realized it's the same as in the docs, which also didn't work for me back then. So currently I'm sticking with the one I mentioned above.

About nginx: I'll be able to test the setup in the upcoming 1-2 weeks.

AlexanderSavelyev commented 3 years ago

We are going to revisit our approach to indigo-service. Most probably we will move nginx into the docker. Will it work for you?

Doidel commented 3 years ago

Yes, this would work for me. This would give me a good deal of flexibility when I can adjust the config.

(Sorry for not having responded to this issue. The project is on ice for at least another 2 months, as currently communicated by my employer)