表示的代理-500次超时-执行多次服务器代码

我不知道发生了什么。当我尝试向后端发送请求以添加关注者(我的路由如下)时,我收到服务器tiemout错误,而不是成功,但是在我的数据库中,关注者被正确添加(并删除),但并非总是如此。有时它保存相同结果的3倍(追随者到db),或者有时不删除关注者。 问题是我不知道发生了什么。

在我的控制台中,我有时会看到此错误: [HPM]尝试将请求/ api / users / user / follow从127.0.0.1:8080代理到http://[::1]:1648(ECONNRESET)(https://nodejs.org/api/errors.html#errors_common_system_errors

时发生错误

setfollower路线:


const setfollowing = async (req,res,next) => {
   try {
      const userId = req.body.userId;
      const followId = req.body.followId;
      await User.findByIdAndUpdate(
         userId,{
            $push: {
               following: followId,},);
      next();
   } catch (err) {
      res.status(400).json({
         error: err,});
   }
};

const setfollower = async (req: Request,res: Response) => {
   try {
      const followId = req.body.followId;
      const userId = req.body.userId;
      const result = await User.findByIdAndUpdate(
         followId,{
            $push: {
               followers: userId,{ new: true },)
         .populate('following','_id name')
         .populate('followers','_id name')

      const followerResult = { ...result._doc };
      const { photo,salt,passwordHash,...rest } = followerResult;

      return res.status({ ...rest });

   } catch (err) {
      res.status(400).json({
         error: err,});
   }
};


router.put(
   '/user/follow',isUserSignIn,setfollowing,setfollower,);



点击按钮发送请求

   try {
         setLoading(true);
         const response = await fetch('/api/users/user/follow',{
            body: JSON.stringify({
               followId: params.userId,userId: loggedInUser._id,}),headers: {
               'accept': 'application/json','Authorization': `Bearer ${token}`,'Content-Type': 'application/json',method: 'PUT',});
         const data = await response.json();


         setLoading(false);
         setfollowing(true);
      } catch (err) {
         if (err.message) {
            setServerError(err.message);
         } else {
            setServerError(JSON.stringify(err));
         }
      }

我的仓库:https://github.com/bartek-fecko/fullstackapp

abc504169814 回答:表示的代理-500次超时-执行多次服务器代码

对于我的假设,给定问题中的日志,您正在使用express。的    关键是在服务器上设置超时属性(以下将超时设置为一个    其次,使用您想要的任何值):

  var server = app.listen(app.get('port'),function() {
       debug('Express server listening on port ' + server.address().port);
        });
       server.timeout = 1000;
本文链接:https://www.f2er.com/3127066.html

大家都在问