3liz / py-qgis-server

QGIS embbeded WMS/WFS/WCS asynchronous scalable http server
https://docs.3liz.org/py-qgis-server
Mozilla Public License 2.0
68 stars 16 forks source link

Cross-Origin Request Blocked - CORS #11

Closed drambourg closed 3 years ago

drambourg commented 4 years ago

Hello, I try to work w/ your docker image. The install is well, and can serve WMS, WFS, using a qgis sample project w/ polygons layer. I want to use it w/ a front mapping framework (OpenLayers 3).

WMS Display layer is well done. I tried to use service as WFS and blocked to a Cross-Origin Request. Same Thing on a GetFeatureInfo on WMS.

I specify and try multiple setting on crossOrigin as anonymous or null, to pass through. But nothing. When i copy url directly in browser, JSON returns right.

Maybe a server configuration to allow anonymous connection in your QGIS Server build. Is it by default set to a CORS anonymous? Do you implement an envirnoment or parameter on launch container to set it?

Thanks in advance. (and your works)

dmarteau commented 4 years ago

Hi,

Thank you for your return.

Is it by default set to a CORS anonymous?

The default configuration is to allow cross origin CORS. If you want restrict to the Origin header of the request then you must set the QGSRV_SERVER_CROSS_ORIGIN variable to no (alternatively, you may set the cross_origin key in section [server] in the configuration file).

Here is the code for reference: https://github.com/3liz/py-qgis-server/blob/master/pyqgisserver/handlers/basehandler.py#L70

Hint: check the headers of the requests to ensure that the value of Access-Control-Allow-Origin is correct.

drambourg commented 4 years ago

Thanks to your answer. I ll come back to feedback when i have some time to continue my sandbox app. Hopefully soon.

dmarteau commented 3 years ago

OPTIONS method have been implemented for CORS context.