Vladimir Zaguzin
Vladimir Zaguzin

Reputation: 303

configure url for react\spring app deployed on tomcat

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?

Upvotes: 0

Views: 173

Answers (1)

best wishes
best wishes

Reputation: 6634

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

Upvotes: 1

Related Questions