【发布时间】: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 上的东西?
【问题讨论】:
-
这些答案有帮助吗?:stackoverflow.com/questions/54308359/…
标签: javascript spring tomcat intellij-idea