React 前端在 Reactjs + Nodejs 应用程序中没有从 nodejs 后端收到 return
React frontend doesn't receive return from nodejs backend in Reactjs + Nodejs App
我的后端登录过程是 运行 在 Nodejs 12.16.1 上。代码如下:
router.post("/elogin", async (req, res) => {
try {
if (!req.body.userName || !req.body.password) throw new Error("No match"); //<<==this line causes error and jump to catch
let emp = await Employee.findOne({where: {username, password}});
if (!emp) throw new Error("No match!");
return res.status(200).send(_.pick(emp, ['id', 'cell', 'cell_country', 'name']))
} catch(err) {
return res.status(400).send("Hi Not working right now"); //<<===this return stuck and never come out.
}
});
在调试中,代码停留在 Bluebird 中的 drainQueues
,根据在线信息,Bluebird 是一个 promise 库。执行永远不会结束并卡在这里。这是一个正常的return
,我看不出它应该如何卡住。
前端是React和Fetch。动作类型无关紧要。 get
也卡住了。
你试试用postman看看能不能returns。如果有,那么可能是后台代码有问题
我的后端登录过程是 运行 在 Nodejs 12.16.1 上。代码如下:
router.post("/elogin", async (req, res) => {
try {
if (!req.body.userName || !req.body.password) throw new Error("No match"); //<<==this line causes error and jump to catch
let emp = await Employee.findOne({where: {username, password}});
if (!emp) throw new Error("No match!");
return res.status(200).send(_.pick(emp, ['id', 'cell', 'cell_country', 'name']))
} catch(err) {
return res.status(400).send("Hi Not working right now"); //<<===this return stuck and never come out.
}
});
在调试中,代码停留在 Bluebird 中的 drainQueues
,根据在线信息,Bluebird 是一个 promise 库。执行永远不会结束并卡在这里。这是一个正常的return
,我看不出它应该如何卡住。
前端是React和Fetch。动作类型无关紧要。 get
也卡住了。
你试试用postman看看能不能returns。如果有,那么可能是后台代码有问题