Saya akhirnya mendapat jawaban untuk apache Tomcat8
Anda harus mengedit file tomcat web.xml.
mungkin itu akan berada di dalam folder webapps,
sudo gedit /opt/tomcat/webapps/your_directory/WEB-INF/web.xml
temukan dan edit
<web-app>
<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>
</web-app>
Ini akan memungkinkan Access-Control-Allow-Origin semua host. Jika Anda perlu mengubahnya dari semua host menjadi hanya host Anda, Anda dapat mengedit
<param-name>cors.allowed.origins</param-name>
<param-value>http://localhost:3000</param-value>
kode di atas dari * ke http Anda : // your_public_IP atau http://www.example.com
Anda dapat merujuk di sini dokumentasi filter Tomcat
Terima kasih