0

i'm learning how to make a webapp with react and spring boot and i'm working in IntelliJ

so far I have a small backend and frontend combo with 1 page a api call that looks like this from the fronend

  handleSubmit(event) {
    fetch( '/api/test', {
      method: 'POST',
      body: JSON.stringify(this.state),
      headers:{
        'Content-Type': 'application/json',
        'test':''
      }
    }).then(res => res.json())
    .then(response => console.log('Success:', JSON.stringify(response)))
    .catch(error => console.warn('Error:', error));
    console.log(JSON.stringify(this.state))
    event.preventDefault();
  }

when i test it with spring configuration and tomcat config in my ide everything works, my code works as i want both on react and spring

but when i build a war file and deploy it directly to the tomcat an address for my app changes from localhost:8080 to localhost:8080/testapp/

but my api call is still looking for localhost:8080/api/test

where should i change the config on frontend to point to a different url or something on my tomcat?

Vladimir Zaguzin
  • 191
  • 5
  • 22
  • Do these answers help?: https://stackoverflow.com/questions/54308359/after-deploying-war-file-in-tomcat-api-not-working#comment95437333_54308359 – Selaron Jan 29 '19 at 15:58

1 Answers1

1

While deploying your app to tomcat, rename the war file to ROOT.war. Then you won't have to append testapp anymore.

best wishes
  • 5,789
  • 1
  • 34
  • 59