Recently, I set up a local Tomcat installation on port 8081 to expose a REST API. However, my development web server operates on port 9000. I want to make calls to the REST API from JavaScript code running in the browser using Angular's $http
. Due to the cross-origin request (CORS), I encountered this error:
"No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access."
To resolve this issue, I followed the documentation and added a filter to the Tomcat configuration:
<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>
Initially, this fix worked for my GET
requests. However, when attempting POST
requests, the same error reappeared. I am puzzled as to why the filter is not allowing POST
requests despite being configured to do so. Any insights on this?