Tuesday, 5 November 2019

Very weird express.js behavior

I have the following route:1.With the console.log("1"), there will be no console printing and it will promptly send the response.2.Without that, there will be console printing as expected.3.If I move res.send to the very end. No console printing appears.getOauthToken is async func(){} returning promisegetParams is func(){}This behavior is so weird, some explanations please :)router.get("/emailBot/:cid", getParams, getOauthToken, async (req, res, next) => {const cid = req.cidconst jwtToken = req.jwtconst apiUrl = process.env.EMAILBOTAPIconst XToken = process.env.EMAILBOTXTOKENconsole.log(jwtToken);try {const apiResponse = await sendMessages.triggerApi(apiUrl, jwtToken, XToken, {invocationContext: {cid: cid}})console.debug(apiResponse)res.send({message: "success"})} catch (error) {next(error)}//console.log("1")})

Submitted November 05, 2019 at 11:01AM by PanJohn2019

No comments:

Post a Comment