如何解决将 POST 获取到 localhost:3000 而不是 localhost:8080
我已将 "proxy": "http://localhost:8080" 添加到我的 package.json 文件中,以便它将 POST 定向到 8080,但它显示 AddBook.js:34 POST http://localhost:3000/api/book 404 (Not Found)
为什么要发送到 3000?
{
"name": "appone-fe","version": "0.1.0","private": true,"dependencies": {
"@material-ui/core": "^4.11.2","@material-ui/icons": "^4.11.2","@testing-library/jest-dom": "^5.11.4","@testing-library/react": "^11.1.0","@testing-library/user-event": "^12.1.10","react": "^17.0.1","react-dom": "^17.0.1","react-scripts": "4.0.1","web-vitals": "^0.2.4"
},"scripts": {
"start": "react-scripts start","build": "react-scripts build","test": "react-scripts test","eject": "react-scripts eject"
},"proxy": "http://localhost:8080","eslintConfig": {
"extends": [
"react-app","react-app/jest"
]
},"browserslist": {
"production": [
">0.2%","not dead","not op_mini all"
],"development": [
"last 1 chrome version","last 1 firefox version","last 1 safari version"
]
}
}
这是我的 handlesubmit 函数,我也试过只发布到“/book”
const handleSubmit = (event) => {
event.preventDefault()
fetch("/api/book",{
method: "POST",headers: {"Access-Control-Allow-Origin": "*"},body: {
...state
}
}).then((a) => {
alert(`status code ===> ${a.status}`)
}).catch(error => alert(error))
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。