3

I am using a GeoServer docker image from here and running a docker container on CentOS Linux. GeoServer Docker

I have mounted Geoserver data directory as external and able to successfully run the GeoServer

I am able to get WFS request without any issue. However when I do Post on WFS. I am getting a CORS error. I am running my web server and docker on same server so IP is same but GeoServer runs 8080 and my NodeJS React app runs on 3000.

Access to XMLHttpRequest at 'http://XXX:8080/geoserver/VPS/ows' from origin 'http://XXX:3000' 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.

Tomcat in the docker container is CORS enabled by default. I tried to enable the CORS in GeoServer webapp folder also.

Still I am getting the same error.

What am I missing here to solve this CORS issue

And my Post call looks like below from React Axios

axios({
  method: 'post',
  headers: { "Access-Control-Allow-Origin": "*", "X-Frame-Options": "SAMEORIGIN", "Content-Type": 'text/xml' },
  url:configData.gs_transactUrl,
  crossdomain: true,
  service: 'WFS',
  version: '1.0.0',
  dataType: 'xml',
  processData: false,
  RequestMethod: "POST",
  contentType: 'text/xml',
  typeName:configData.gs_typeName,
  data: myXMLdata
}).then(function (response) {
//do something here
}
6
  • 1
    As the message says, you probably need to set the Access-Control-Allow-Origin header. More on this can be found here: developer.mozilla.org/fr/docs/Web/HTTP/Headers/… Commented Jul 14, 2021 at 12:45
  • @swiss_knight I tried to add CORS header on my ExpressJS so for request it passes the headers. But Still its getting same error. Access-Control-Allow-Origin I set to * and also IP but no success const cors=require('cors'); const corsOptions={ origin: '*', optionsSuccessStatus: 200, credentials:true, preflightContinue:true, };
    – Senthil S
    Commented Jul 14, 2021 at 12:56
  • are you sure tomcat has CORS on by default? I don't think it does. see gis.stackexchange.com/questions/370605/…
    – Ian Turton
    Commented Jul 14, 2021 at 13:07
  • @IanTurton, In the docker image (mentioned above in link) which I am using, it is enabled by default. Also I have verified that it has CORS filters in place
    – Senthil S
    Commented Jul 14, 2021 at 13:14
  • Then as @swiss_knight says you aren't correctly setting the Access-control-allow-origin header
    – Ian Turton
    Commented Jul 14, 2021 at 13:34

1 Answer 1

1

in order to enable the CORS on GeoServer you will need to tweak this option on the GEOSERVER_JAVA_OPTS variable of the .env file:

-DGEOSERVER_CSRF_DISABLED=true

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.