Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue Enabling CORS #24

Closed
BootstrapB opened this issue Jan 11, 2018 · 4 comments
Closed

Issue Enabling CORS #24

BootstrapB opened this issue Jan 11, 2018 · 4 comments

Comments

@BootstrapB
Copy link

BootstrapB commented Jan 11, 2018

I need CORS enabled so I can get WMS layers from geoserver with Cesium. When running my own version of geoserver(not dockerized) I just edit /tomcat/webapps/geoserver/WEB-INF/web.xml and uncomment the CORS filters. I copied the web.xml file, edited it, and then ran docker with the new web.xml mounted by doing: docker run --name "geoserver" --link postgis:postgis -v ~/web.xml:/usr/local/tomcat/webapps/geoserver/WEB-INF/web.xml -p 8080:8080 -d -t kartoza/geoserver

After making this change when I got to localhost:8080/geoserver/index.html I get a 404 error. Any idea why this is happening or know of a way to enable CORS?

EDIT: Please close this issue, I realized I was editing the wrong the web.xml file. For anyone having this issue, you have to edit the /tomcat/conf/web.xml (not /tomcat/webapps/geoserver/WEB-INF/web.xml) file and in the filter section add this:

CorsFilter org.apache.catalina.filters.CorsFilter CorsFilter /*
@ericsvendsen
Copy link

Took me a while to figure out what exactly needed to be added based on your edited comment. Here it is in case anyone else looking at this is as clueless as me 😀

<filter>
    <filter-name>CorsFilter</filter-name>
    <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>CorsFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

@BootstrapB
Copy link
Author

Oops sorry about it being unclear, the formatting must have messed up when I pasted my code. Thanks for making it more clear!

@eg-novelt
Copy link

eg-novelt commented Jul 27, 2018

Hello, for me what worked was a few extra init-params, in /usr/local/tomcat/conf/web.xml as follows:

<filter>
    <filter-name>CorsFilter</filter-name>
    <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
    <init-param>
        <param-name>cors.allowed.origins</param-name>
        <param-value>*</param-value>
    </init-param>
    <init-param>
        <param-name>cors.allowed.headers</param-name>
        <param-value>If-Mofidied-Since,Range,Origin</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>CorsFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

@JWDobken
Copy link

JWDobken commented Dec 6, 2018

This solved my problem!

However, I still get these console errors:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8600/geoserver/test/wms?bbox=-672645.8489095494,4263351.689633992,-670199.8640044257,4265797.674539115&format=image/png&CRS=EPSG:3857&service=WMS&version=1.3&request=GetMap&srs=EPSG:3857&transparent=true&width=256&height=256&layers=test:T1. (Reason: CORS request did not succeed).[Learn More]

Can this be a feature implementation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants