API routes with Promise.all #16862
Answered
by
timneutkens
Nick-Mazuk
asked this question in
Help
-
Whenever I use Promise.all inside an API route, I get the following error. API resolved without sending a response for /api/route, this may result in stalled requests. I suspect NextJS assumes that since it's reached the end of the function and hasn't found a Here's a barebones file that demonstrates this behavior: // api/route
const promise = () => {
return new Promise((resolve, reject) => {
resolve()
})
}
export default (req, res) => {
Promise.all([promise]).then(() => {
res.statusCode = 200
res.json({ message: 'Success!' })
}).catch((e) => {
res.statusCode = 200
res.json({ message: 'Success!' })
})
} |
Beta Was this translation helpful? Give feedback.
Answered by
timneutkens
Sep 6, 2020
Replies: 1 comment 1 reply
-
You need to |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Nick-Mazuk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to
await
the promise.