📚 [Tomcat] Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Category: Tomcat | 📅 April 12, 2018
톰캣 CORS 필터 설정으로 처리 하자.
$sudo vim /etc/tomcat8/web.xml
tomcat8을 소스로 설치한 경우는 WEB-INF/web.xml 을 열어서 붙여 넣으면 됨.
톰캣8 CORS 필터 설정하기
이동하기 귀찮은 분들을 위하여.. (위 링크에서 퍼왔음. 내용은 필요에 따라 수정 되어야 함.)
<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.methods</param-name>
<param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.headers</param-name>
<param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
</init-param>
<init-param>
<param-name>cors.exposed.headers</param-name>
<param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
</init-param>
<init-param>
<param-name>cors.support.credentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.preflight.maxage</param-name>
<param-value>10</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
그리고 재시작.
$sudo service tomcat8 restart