-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow after request middleware #1301
Comments
I recently came across this issue and ended up with something like (StackBlitz), // middleware/afterware.ts
export default eventHandler((event) => {
const start = Date.now();
event.res.once('close', () => {
const ms = Date.now() - start;
console.log(`Request took ${ms}ms`);
});
}); This was based on the node middleware helper function approach here in the h3 library. Just noticed a recent change unjs/h3#482 that has added the ability to add before/after hooks to h3 though. Could this be used to implement this functionality in Nitro using unjs/hookable? |
@gnoeley yes that's the plan! You would be able to use nitro app hooks to leverage them. |
If more hooks are to be added to Nitro, is there a plan to document them more clearly either as a main-section in docs? To date, I've been grepping the code to find our what was supported. Looks like they are all listed under Plugins->Examples currently, but perhaps calling them out directly could be useful. It was a point of confusion for me personally at least 😅 Happy to raise a PR if that would be welcome? |
Certainly! I will make sure to at least write clear usage in PR description. You are always more than welcome to contribute and improve docs and examples ❤️ |
@pi0 , I've opened a draft PR with some proposed documentation changes. I've had a guess at what the final API for the addition of the new hooks could be, happy to accept comments once that is finalized and I can update. Can have any further discussion in the PR. |
Describe the feature
Hello,
I was thinking about after middleware like in express.
For example, if I've a middleware like this:
And a route like this:
I expect:
This is not an API to implement but juste an example of what I've in mind
nuxt/nuxt#21522
Additional information
The text was updated successfully, but these errors were encountered: