There have been lot of discussions about CORS and 'Access-Control-Allow-Origin' error, I have tried and read(doing it for 2 days now) lots of potential solutions but my concern is where to place the solution code. How and in which file do I need to make changes for header to give Access to all cross server calls. I am using Ember CLI, Tomcat Apache(which is getting data from database), running on Chrome, and using ember-data. May be a noob question but I really am not able to get out of it, really need help. Thanks in Advance.
UPDATE: I am running Apache Tomcat 7 via eclipse and using simple JAVA OracleJDBC request/response to get data.
Basically this error is not of the Ember-Cli. This is what your server (tomcat in your case) is responding, when your Ember application is communicating to your server. I don't know what version are you using of TomCat. But I will illustrate to you how to fix this problem in TomCat 7.
Open your web.xml
file. It will be located in {apache-tomcat-directory}/conf/
. You can add the filter to alter the CORS behavior anywhere in the file after the web-app
root of XML file. But I will suggest you to do that after the portion of Built in Filter Mappings
.
The filter will look like this:
<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>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
After adding this you will be able to bypass this error. But this is only recommended if you are doing it for development purposes. Please read here for complete understanding of TomCat's CORS filter.