Deploy war with Spring boot app and react app in Tomcat

Viewed 412

I have the backend with Spring Boot and the frontend with React. I'm trying to deploy all in a war to Tomcat 9.0.56.

In the Spring Boot I put in the properties:

spring.resources.static-locations=classpath:/build/
spring.thymeleaf.prefix=classpath:/build/

In the react app in the package.json I have:

"homepage": "localhost:8080"

Then I build the react app and put it in the folder api/src/main/resources/build

I build the war and deploy it as ROOT.war

When I enter to the application it wont load as it don't find the js and css, it looks like a CORS problem of Tomcat: Problem in tomcat

This only happen with react apps, because if I put a single html page, it works fine.

I try configuring CORS in Tomcat with:

 <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>

but it doesn't work either.

Any idea?

Thanks!!

1 Answers
Related