Select to view content in your preferred language

CORS error when adding WMS layers from Geoserver layer

5181
4
Jump to solution
12-17-2021 12:53 AM
Vakhtang_Zubiashvili
Frequent Contributor

Hi Guys, need help. I try add GeoServer wms layer on my webmap. It was working good about few days ago, but now i get error: Access to fetch at 'http://nv1.reestri.gov.ge/geoserver/wms?SERVICE=WMS&REQUEST=GetCapabilities' from origin 'http://10.0.124.10' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. (See PIC)

I use standard code to add layer:

 

 

const registrirebuli_nakvetebi = new WMSLayer({
          url: "http://nv1.reestri.gov.ge/geoserver/wms",
          title: "xxx",
          visible: true,
          sublayers: [
            {
              name: "LR_PARCELS"
            }
          ]
        });  
        map.add(registrirebuli_nakvetebi)

 

 

How can i handle this? Geoserver is not on my hand, so i can not enable/disable CORS.

0 Kudos
1 Solution

Accepted Solutions
B-L
by
Occasional Contributor

Looking into this, i saw the following in the api docs.

"The WMSLayer initially executes a WMS GetCapabilities request, which might require CORS or a proxy page."   (source:https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-WMSLayer.html )

Since you are unable to enable/disable CORS you may need to look into a proxy. 

https://developers.arcgis.com/javascript/latest/proxies/

 

I have had some success with this proxy in the past with handling CORS issues https://github.com/Esri/resource-proxy

HOWEVER, esri has since added the following disclaimer 

"We don't recommend using this resource proxy. It is not being maintained and there's been no active development for many years. There are many better solutions." 

But at the very least, the GIT README can shed some light on how a proxy can be integrated depending on your environment. 

I hope that helps!

View solution in original post

4 Replies
B-L
by
Occasional Contributor

Looking into this, i saw the following in the api docs.

"The WMSLayer initially executes a WMS GetCapabilities request, which might require CORS or a proxy page."   (source:https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-WMSLayer.html )

Since you are unable to enable/disable CORS you may need to look into a proxy. 

https://developers.arcgis.com/javascript/latest/proxies/

 

I have had some success with this proxy in the past with handling CORS issues https://github.com/Esri/resource-proxy

HOWEVER, esri has since added the following disclaimer 

"We don't recommend using this resource proxy. It is not being maintained and there's been no active development for many years. There are many better solutions." 

But at the very least, the GIT README can shed some light on how a proxy can be integrated depending on your environment. 

I hope that helps!

Vakhtang_Zubiashvili
Frequent Contributor

Hi Again,

So, i followed these documentation, but still got CORS error. When i set all correctly now it says that there are multiple headers.  

0 Kudos
Vakhtang_Zubiashvili
Frequent Contributor

Hi @B-L ,

So, i have configured proxy using your suggestions. Now maps loads, from proxy server i get response like this: https://nv.napr.gov.ge/geoserver/ows?width=1920&height=523&bbox=4980332.152501735%2C5119742.33096146...

but it does not appear on map, still get CORS error: Access to image at 'https://nv.napr.gov.ge/geoserver/ows?width=1920&height=485&bbox=4834810.382589555%2C5082880.57407094...' from origin 'http://10.0.124.10' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

 

What else i have to do? I think it should work now, but no success. 

0 Kudos
B-L
by
Occasional Contributor

Hi @Vakhtang_Zubiashvili ,

I would highly recommend that you reach out to ESRI support on this one. Especially since it is dealing with CORS and Proxies, which can both come with some security considerations. Best of luck!

 

 

 

0 Kudos