【问题标题】:configure url for react\spring app deployed on tomcat为部署在 tomcat 上的 react\spring 应用配置 url
【发布时间】:2019-06-22 18:28:59
【问题描述】:

我正在学习如何使用 react 和 spring boot 制作一个 webapp,我正在使用 IntelliJ

到目前为止,我有一个小型后端和前端组合,其中包含 1 页的 api 调用,从前端看起来像这样

  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();
  }

当我在我的 ide 中使用 spring 配置和 tomcat 配置对其进行测试时,一切正常,我的代码在 react 和 spring 上都可以正常工作

但是当我构建一个war文件并将其直接部署到tomcat时,我的应用程序的地址从localhost:8080更改为localhost:8080/testapp/

但我的 api 调用仍在寻找 localhost:8080/api/test

我应该在哪里更改前端的配置以指向不同的 url 或我的 tomcat 上的东西?

【问题讨论】:

标签: javascript spring tomcat intellij-idea


【解决方案1】:

在将应用部署到 tomcat 时,将 war 文件重命名为 ROOT.war。这样你就不必再附加 testapp 了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-06
    • 1970-01-01
    • 2012-11-11
    • 2020-04-17
    • 2014-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多