我正在尝试在开发模式下设置react和spring boot,我有运行前端和后端的独立端口,即http://localhost:3000/api/hello和http://localhost:8080/api/hello。我喜欢在后台调用服务,并在前端显示结果,为此我在react应用程序的package.json文件中添加了"proxy":"http://localhost:8080“。但它不起作用。
请帮帮我怎么修?
package.json文件
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-scripts": "1.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:8080",
}我可以显示带有前端reactjs代码的后端弹簧启动代码
发布于 2019-08-27 23:13:07
您不必定义代理端口。只需运行spring boot项目,然后从react应用程序发送请求
例如在React中:
fetch("http://localhost:portNumber/login", {
method: 'POST',
headers: {'content-type': 'application/json'},
body: JSON.stringify({
email: this.state.emailAddress,
password: this.state.password})
})
.then(resopnse => {
if(response.status === 200){
}
})Spring boot:
@CrossOrigin("*")
@PostMapping("/login")
public userLogin(@RequestedBody modalName objectname){
//Service Call
} https://stackoverflow.com/questions/57610862
复制相似问题