spacy-api-docker icon indicating copy to clipboard operation
spacy-api-docker copied to clipboard

Request from another container

Open KaNuNSuZoFLu opened this issue 7 years ago • 2 comments

I‘m getting an error (Cross origin) when I am doing a request from another container. How can I enable cors?

KaNuNSuZoFLu avatar Nov 18 '18 22:11 KaNuNSuZoFLu

Hmm, interestingly I haven't run into that problem myself so far. How exactly are you making your request?

A fix could be adding this middleware https://github.com/falconry/falcon/issues/1220#issuecomment-363266844 to the Python code here https://github.com/jgontrum/spacy-api-docker/blob/a33fd3c6c58d4883f071d681484b03ede9557eb6/displacy_service/server.py#L151 I don't know how soon I have time to integrate it, so feel free to make a PR :)

jgontrum avatar Nov 19 '18 11:11 jgontrum

Hi, so I was on the right path. exactly there I wanted to add the cross_origin but I was not sure, if the mistake is not my request itself. I tried to make an ajax request.

first of all i created the container a bit different, because I want to make the request from another docker container, so i created the container like

docker run -it -p "0.0.0.0:8080:80" jgontrum/spacyapi:en_v2

I have a nodejs container, where my application is hosted on. the request is done from a javascript

$.ajax({ type: "PUT", url: "http://:8080/ent", contentType: 'application/json; charset=utf-8', data: JSON.stringify({ "text": "When Sebastian Thrun started working on self-driving cars at Google in 2007, few people outside of the company took him seriously.", "model": "en" }), dataType: 'json', async: true, success: function() { console.log("success"); }, error: function() { console.log("error"); } });

I think the request should be right. and the error which is given is:

Access to XMLHttpRequest at 'http://<my_ip>:8080/ent' from origin 'http://<my_ip>:<nodejs_port>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Thanks for your help

KaNuNSuZoFLu avatar Nov 19 '18 13:11 KaNuNSuZoFLu