restify / node-restify

The future of Node.js REST development
http://restify.com
MIT License
10.71k stars 981 forks source link

Res.redirect won't work for async routes at all? #1973

Open jurijus01 opened 3 months ago

jurijus01 commented 3 months ago

Hello Restify!

Don't know whether it's a bug or feature request. My case is as follows:

I have an async route

server.get("/verify", async (req, res) => {}

containing interaction with MongoDB via Mongoose. In that route I need to use res.redirect, which won't work, because, apparently, it needs "next", which is not declared in async routes.

I tried going the ugly "Callback Hell" way and rewriting everything without await/async, but, apparently, Mongoose no longer supports callbacks - for all the good reasons. It gave an error:

MongooseError: Model.findOne() no longer accepts a callback

Please help with an advice how to make res.redirect work in async routes.