Enable CORS

To enable CORS for your Tomcat instance, you can use our included file.

This file is located under /scripts/cors.txt

The contents should be added to the line just before </web-app> in your /home/tomcat/apache-tomcat-{version}/conf/web.xml

Warning

Be sure to create a backup of your web.xml file before making any changes.

The file Contents are below

 1         <filter>
 2         <filter-name>CorsFilter</filter-name>
 3         <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
 4         <init-param>
 5               <param-name>cors.allowed.origins</param-name>
 6               <param-value>*</param-value>
 7         </init-param>
 8         <init-param>
 9               <param-name>cors.allowed.methods</param-name>
10               <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
11         </init-param>
12         </filter>
13         <filter-mapping>
14         <filter-name>CorsFilter</filter-name>
15         <url-pattern>/*</url-pattern>
16         </filter-mapping>

You must restart Tomcat for the changes to register.

Note

The above script is very permissive. You should refine your CORS filter to reflect usage.