Skip to content
Discussion options

You must be logged in to vote

Actually looking further into it, I think I've found the perfect solution!

I totally forgot that the NodeJS Response object itself already has lifecycle hooks. So I can hook into those to do what I want, such as:

ctx.res.on("finish", async () => {
  // You MUST use `res` not `response` to get the NodeJS object, rather than the KoaJS object
  // But now here you can do all your after response work, and if defined where you already have a `ctx` you'll still have it
});

Just tested it out and it seems to work exactly as I'd hope, retaining the context object and executing after the user gets the request, so we are good to go!

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by confused-Techie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant