【发布时间】:2022-01-04 20:15:57
【问题描述】:
我正在托管一个 Flask 后端,该后端部署在例如后端.herokuapp.com/test。我现在正试图让我部署的 React 前端(例如 frontend.herokuapp.com)连接到这个后端:
useEffect(() => {
fetch("/test", {
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
},
}).then((response) =>
response.json().then((data) => {
setTest(data.tests);
})
);}, []);
为了开发,我在package.json 中使用了代理:
"proxy": "http://localhost:5000"
但现在在生产中,我想在没有 localhost 的情况下访问我的后端。我怎样才能做到这一点?我还需要代理吗?因为我的前端现在自动使用请求 URL:frontend.herokuapp.com/test 而不是 backend.herokuapp.com/test。
【问题讨论】:
标签: reactjs flask heroku url fetch