API не возвращает ответ почтальону - PullRequest
0 голосов
/ 24 апреля 2020

Я занимаюсь разработкой API с использованием node js и mongodb. Для тестирования API я использую node js. Я не получаю никакой ошибки. Но дело в том, что в почтальоне это показывает, что не может получить ответ, а в консоли вывод отличный. Код занимает много времени для выполнения. Следовательно, запрос в почтальоне истек. Но код выполняется отлично. Через некоторое время он показывает JS stacktrace error и node app crash error. Пожалуйста, помогите мне, спасибо.

код контроллера идет здесь:

exports.user_signup = async (req, res, next) => {
  const { error } = registerValidation(req.body);
  if (error)
    return res.status(400).json({
      message: error.details[0].message,
    });
  User.findOne({ email: req.body.email })
    .exec()
    .then((user) => {
      if (user) {
        return res.status(409).json({
          result: 0,
          message: "Email has been already registered.",
        });
      } else {
        bcrypt.hash(req.body.password, 10, (err, hash) => {
          if (err) {
            return res.status(500).json({
              error: err,
            });
          } else {
            const newUser = new User({
              userID: " ",
              name: req.body.name,
              email: req.body.email,
              password: hash,
              latitude: req.body.latitude,
              longitude: req.body.longitude,
              registrationIP: req.body.registrationIP,
              isp: req.body.isp,
              location: req.body.location,
              reference: req.body.reference,
            });
            newUser
              .save()
              .then((result) => {
                User.updateOne(
                  { idCounter: newUser.idCounter },
                  { $set: { userID: "AE-" + newUser.idCounter } },
                  { useFindAndModify: false }
                ).exec();
                const token = jwt.sign(
                  { userid: result._id, loginid: result.email },
                  config.env.JWT_KEY
                );
                var transporter = nodemailer.createTransport({
                  host: config.env.MAIL_HOST,
                  port: 587,
                  secure: false, // true for 465, false for other ports
                  auth: {
                    user: config.env.MAIL_USER,
                    pass: config.env.MAIL_PASS,
                  },
                });
                var host = config.env.LOCAL_HOST;
                let userName = result.name;
                link = `${host}/verify?email=${result.email}&token=${token}`;
                var mailOptions = {
                  from: "Account-Era <noreply@accountera.app>",
                  to: req.body.email,
                  subject: "Registered",
                  text: "",
                  html: `<link href="https://fonts.googleapis.com/css?family=Poppins:400,500&display=swap" rel="stylesheet"> ​<table cellpadding="0" cellspacing="0" border="0" align="center" width="100%" bgcolor="#FFFFFF"><tbody><tr><td><table cellpadding="0" cellspacing="0" border="0" align="center" width="700" bgcolor="#FFFFFF" style="margin:0 auto"><tbody><tr><td align="center"><table cellpadding="0" cellspacing="0" border="0" width="480"><tbody><tr><td bgcolor="#FFFFFF" height="20" style="line-height:20px;font-size:20px">&nbsp;</td></tr><tr><td align="center"><table width="100%" bgcolor="#FFFFFF" cellpadding="0" cellspacing="0" border="0" align="center"><tbody><tr><td align="left" style="line-height:45px"> <img src="https://s3.ap-south-1.amazonaws.com/accountera.app/main-assets/email/logo.png" height="15" width="auto" style="display:block;padding:0px;text-align:left;border:0px none transparent" alt="Logo"></td></tr></tbody></table></td></tr><tr><td bgcolor="#FFFFFF" height="20" style="line-height:20px;font-size:20px">&nbsp;</td></tr></tbody></table><table cellpadding="0" cellspacing="0" border="0" width="480" class="card" bgcolor="#ffffff" style="border:1px solid #dadce0;border-radius:8px"><tbody><tr class="body-outer-spacer"><td align="center" height="25" style="font-size:1px;line-height:1px">&nbsp;</td></tr><tr><td align="center" valign="middle"><table cellpadding="0" cellspacing="0" border="0" width="420" bgcolor="#ffffff"><tbody><td align="center" style="font-family:Arial,sans-serif"><div style="font-size:20px;font-family:Poppins,Helvetica,Arial,sans-serif!important;color:#666666;line-height:1;text-align:center">Hello <span>${userName}</span>,</div></td><tr class="body-inner-spacer"><td height="24" style="font-size:1px;line-height:1px">&nbsp;</td></tr><tr><td height="auto" width="360" valign="top" align="center" style="color:#666666;font-family:Poppins,Helvetica,Arial,sans-serif!important;font-size:14px;line-height:25px;font-weight:normal">Your email address has been registered with Account-Era. This is a confirmation mail to verify your email address and to validate your account and activate it. <br> <br>You're set to go! Before that, you are supposed to complete the payment process. To complete the payment process click the button "Pay now" right down below.</td></tr><tr class="body-inner-spacer"><td height="24" style="font-size:1px;line-height:1px">&nbsp;</td></tr><tr><td align="center"><table width="100" bgcolor="#FFFFFF" cellpadding="0" cellspacing="0" border="0" align="center"><tbody><tr><td align="center" style="border-radius:4px" bgcolor="#4169e1"> <a href= ${link} style="font-size:14px;font-family:Poppins,Helvetica,Arial,sans-serif;color:#ffffff;text-decoration:none;border-radius:4px;padding:10px 12px;border:1px solid #4169e1;display:inline-block;font-weight:normal;width:100px" target="_blank">Pay now</a></td></tr></tbody></table></td></tr><tr class="body-inner-spacer"><td height="24" style="font-size:1px;line-height:1px">&nbsp;</td></tr><tr><td height="auto" width="360" valign="top" align="center" style="color:#666666;font-family:Poppins,Helvetica,Arial,sans-serif!important;font-size:14px;line-height:25px;font-weight:normal">If you did not associate your email address with an Account-Era, please ignore this message and do not click on the button above.</td></tr><tr class="body-inner-spacer"><td height="24" style="font-size:1px;line-height:1px">&nbsp;</td></tr><tr><td height="auto" width="360" valign="top" align="center" style="color:#666666;font-family:Poppins,Helvetica,Arial,sans-serif!important;font-size:14px;line-height:25px;font-weight:normal">For more information please logon <span><b><a href="https://accountera.app/" target="_blank" style="font-family:Poppins,Helvetica,Arial,sans-serif;color:#666666;text-decoration:none;">accountera.app</a></b></span></td></tr></tbody></table></td></tr><tr class="body-outer-spacer"><td align="center" height="25" style="font-size:1px;line-height:1px">&nbsp;</td></tr></tbody></table><table cellpadding="0" cellspacing="0" border="0" width="480" class="card-spacer"><tbody><tr><td height="20" style="line-height:20px;font-size:20px">&nbsp;</td></tr></tbody></table><table cellpadding="0" cellspacing="0" border="0" width="480"><tbody><tr><td align="center" style="border-bottom:#dadce0 solid 1px"><table align="center" width="100%" bgcolor="#FFFFFF" cellpadding="0" cellspacing="0" border="0"><tbody><tr><td align="center"><table width="480" cellpadding="0" cellspacing="0" border="0" align="center"><tbody><tr><td align="left" height="25" valign="top" style="font-size:1px;line-height:1px" colspan="2">&nbsp;</td></tr><tr><td align="center"><table width="320" cellpadding="0" cellspacing="0" border="0" align="center"><tbody><tr><td align="center" width="80"> <a href="https://www.facebook.com/accountera.application/" style="text-decoration:none" target="_blank"> <img src="https://s3.ap-south-1.amazonaws.com/accountera.app/main-assets/email/facebook.png" border="0" width="40" height="38" alt="Facebook"> </a></td><td align="center" width="80"> <a href="https://www.twitter.com/accountera_app/" style="text-decoration:none" target="_blank"> <img src="https://s3.ap-south-1.amazonaws.com/accountera.app/main-assets/email/twitter.png" border="0" width="40" height="40" alt="Twitter"> </a></td><td align="center" width="80"> <a href="https://www.instagram.com/accountera.application/" style="text-decoration:none" target="_blank"> <img src="https://s3.ap-south-1.amazonaws.com/accountera.app/main-assets/email/instagram.png" border="0" width="40" height="40" alt="Instagram"> </a></td><td align="center" width="80"> <a href="https://youtube.com/" style="text-decoration:none" target="_blank"> <img src="https://s3.ap-south-1.amazonaws.com/accountera.app/main-assets/email/youtube.png" border="0" width="40" height="40" alt="YouTube"> </a></td></tr></tbody></table></td></tr><tr><td align="left" height="35" valign="top" style="font-size:1px;line-height:1px;border-bottom:1px solid #dadce0">&nbsp;</td></tr><tr><td align="left" height="28" valign="top" style="font-size:1px;line-height:1px">&nbsp;</td></tr><tr><td align="center" valign="top" style="font-family:Poppins,Helvetica,arial,sans-serif;font-size:14px;line-height:20px;color:#666666;padding-left:45px;padding-right:45px"> <a href="https://books.accountera.app/" style="text-decoration:none;border-bottom:1px solid #dadce0;color:#666666;white-space:nowrap" target="_blank">View Web Version</a> <span>&nbsp;&nbsp;&nbsp;&nbsp;</span> <a href="#" style="text-decoration:none;border-bottom:1px solid #dadce0;color:#666666;white-space:nowrap" target="_blank">Privacy Policy</a></td></tr><tr><td align="left" height="20" valign="top" style="font-size:1px;line-height:1px">&nbsp;</td></tr><tr><td align="center" valign="top" style="font-family:Poppins,Helvetica,arial,sans-serif;font-size:13px;line-height:20px;color:#666666">You received this mail from <span>Account-Era</span> since you have registered for our services. So we are sharing required and relevant information to you. If you consider the content of this email inappropriate, forward this email to: <span><a href="mailto:report@accountera.app" style="font-family:Poppins,Helvetica,arial,sans-serif;color:#666666;">report@accountera.app</a></span></td></tr><tr><td align="left" height="20" valign="top" style="font-size:1px;line-height:1px">&nbsp;</td></tr><tr><td align="center" valign="top" style="font-family:Poppins,Helvetica,arial,sans-serif;font-size:13px;line-height:20px;color:#666666">© 2019 <span>Account-Era</span>, BTM Layout, Bengaluru, Karnataka - 560068, India</td></tr><tr><td align="left" height="30" valign="top" style="font-size:1px;line-height:1px">&nbsp;</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table>`,
                };
                transporter.sendMail(mailOptions, (error, info) => {
                  if (error) {
                    console.log(error);
                  } else {
                    console.log("Email info", info.response);
                  }
                });
                res.status(200).json({
                  result: 1,
                  userCreated: true,
                });
              })
              .catch((err) => {
                res.status(500).json({
                  error: err,
                });
              });
          }
        });
      }
    })
    .catch((err) => {
      res.status(500).json({
        error: err,
      });
    });
};
...