EIDA / mediatorws

EIDA NG Mediator/Federator web services
GNU General Public License v3.0
6 stars 6 forks source link

CORS #58

Closed Jollyfant closed 5 years ago

Jollyfant commented 5 years ago

Since the Federator now works well I am changing some data quality interfaces to use it! However it seems CORS is not yet enabled. Should we introduce a decorator or something that patches the response? What is the best place to implement this:

response.headers.add("Access-Control-Allow-Origin", "*")
response.headers.add("Access-Control-Allow-Headers", "*")
response.headers.add("Access-Control-Allow-Methods", "*")
Jollyfant commented 5 years ago

We can add flask-cors to Federator venv:

pip install flask-cors

And add the import behind:

https://github.com/EIDA/mediatorws/blob/89c0676fc1d95356b2b7ee8471dbaed7518435d7/eidangservices/federator/server/app.py#L42

from flask_cors import CORS

Patch the app here:

https://github.com/EIDA/mediatorws/blob/89c0676fc1d95356b2b7ee8471dbaed7518435d7/eidangservices/federator/server/app.py#L255

CORS(app)
Jollyfant commented 5 years ago

I monkey patched my service with this change and it works but maybe you have a better solution. I can make a pull request but I'd like your advice on all places where to add the new library (e.g. so dependencies are resolved during installation).

damb commented 5 years ago

Hi @Jollyfant,

first, thanks. I checked flask-cors it seems fine for me. It seems under active development.

I rather would enable CORS within the create_app factory function for each service.

Attached a patch containing the changes necessary. Could you please check if this is working for you? Thx.

Attachments:

Jollyfant commented 5 years ago

Continued in #59