Open matamadio opened 4 years ago
I've created related ticket in JIRA : https://jira.camptocamp.com/browse/GSWBTH-37
I've added CORS header on API on int.thinkhazard.org see: http://int.thinkhazard.org/fr/hazardcategory/EQ/LOW.json
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
Hey did anyone have a solution on https://jira.camptocamp.com/browse/GSWBTH-37? I can not access this link unfortunately.
Hi Rob,
thanks for the feedback. CORS access should've been working, let me paste your message to help with solution:
I was trying to use your API by making a request through the client, and I received a CORS error. This error does not appear in Postman or when I request data through the server. However, for my use case I would like to request the data through the browser. Is there a reason why I am getting this error? I am using the "useSWR" package for ReactJS in case that makes any sense. It would be great if you could explain me the solution!
Just tried with https://www.thinkhazard.org/fr/hazardcategory/FL/MED.json Seems CORS headers are correct:
$ curl -v https://www.thinkhazard.org/fr/hazardcategory/FL/MED.json
< HTTP/1.1 200 OK
< Server: gunicorn/20.0.4
< Date: Wed, 17 Feb 2021 12:04:37 GMT
< Set-Cookie: _LOCALE_=fr; Max-Age=12096000; Path=/; expires=Wed, 07-Jul-2021 12:04:37 GMT
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET
< Content-Type: application/json
< Content-Length: 33094
< Last-Modified: Tue, 30 Jun 2020 15:57:03 GMT
Could you give the url and the error message.
Hi Arnaud, thanks for checking the issue. Here is the link that I used: http://thinkhazard.org/en/report/177.json
And here is a reproduction of my attempt: https://github.com/RobSchilderr/useSWRGetServer
Just tried with https://www.thinkhazard.org/fr/hazardcategory/FL/MED.json Seems CORS headers are correct:
$ curl -v https://www.thinkhazard.org/fr/hazardcategory/FL/MED.json < HTTP/1.1 200 OK < Server: gunicorn/20.0.4 < Date: Wed, 17 Feb 2021 12:04:37 GMT < Set-Cookie: _LOCALE_=fr; Max-Age=12096000; Path=/; expires=Wed, 07-Jul-2021 12:04:37 GMT < Access-Control-Allow-Origin: * < Access-Control-Allow-Methods: GET < Content-Type: application/json < Content-Length: 33094 < Last-Modified: Tue, 30 Jun 2020 15:57:03 GMT
Could you give the url and the error message.
This link does work indeed. :)
Sorry but http://thinkhazard.org/en/report/177.json is not part of the API routes which supports cross origin requests.
The routes that support CORS are:
/admindiv_hazardsets/{hazardtype:([A-Z]{2})}.json
/hazardcategory/{hazard_type:([A-Z]{2})}/{hazard_level:([A-Z]{3})}.json
CORS headers are not added on other routes.
Sorry but http://thinkhazard.org/en/report/177.json is not part of the API routes which supports cross origin requests.
The routes that support CORS are:
/admindiv_hazardsets/{hazardtype:([A-Z]{2})}.json
/hazardcategory/{hazard_type:([A-Z]{2})}/{hazard_level:([A-Z]{3})}.json
CORS headers are not added on other routes.
Alright, thanks for answering :)
We need to provide API access to TH db for external users. Currently, they have issues using the queries from external domains. Here is the message: