【发布时间】:2019-10-31 23:58:27
【问题描述】:
我在 axios 中使用从我的 React JS 前端到我的 Node JS 后端服务器的发布请求。
我的前端在 localhost:3000 上运行,而我的后端在 localhost:8080 上运行。
我的前端代码:
foo = async () => {
const data = {
"data": "data",
};
const response = await axios.post('http:localhost:8080/createUser',data);
console.log(response);
};
我的后端代码:
app.post("/createStripeConnectedAccount", async function (req, res) {
const data = req.body;
// do some login here
res('1')
});
但我在前端收到此错误:
xhr.js:166 POST http://localhost:3000/localhost:8080/createStripeConnectedAccount 404 (Not Found)
由于某种原因,post 请求同时发送到两个域。
【问题讨论】:
-
其实是错字,http://不是http
-
http:localhost:8080/createUser