Skip to content
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

feat(app): onRequest, onBeforeResponse and onAfterResponse global hooks #482

Merged
merged 4 commits into from
Aug 2, 2023

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Aug 2, 2023

πŸ”— Linked issue

Resolves #447

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR adds 3 new global hooks (options) onRequest(event), onBeforeResponse(event, { body }), onAfterResponse(event, { body }?) useful for debugging and request/response interception.

Notes:

  • All hooks support async but it is highly discouraged to avoid Promises and block all requests
  • The onResponse hooks, only receive response with body when a handled directly returns it (not when using send* methods).
  • Only one hook is supported in h3 level. Frameworks can leverage unjs/hookable to support more advanced integrations.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codecov
Copy link

codecov bot commented Aug 2, 2023

Codecov Report

Merging #482 (3cb4a43) into main (21ed8d1) will increase coverage by 0.30%.
The diff coverage is 87.50%.

@@            Coverage Diff             @@
##             main     #482      +/-   ##
==========================================
+ Coverage   82.25%   82.56%   +0.30%     
==========================================
  Files          28       28              
  Lines        3206     3234      +28     
  Branches      489      495       +6     
==========================================
+ Hits         2637     2670      +33     
+ Misses        569      564       -5     
Files Changed Coverage Ξ”
src/app.ts 97.42% <87.50%> (-0.53%) ⬇️

... and 1 file with indirect coverage changes

@pi0 pi0 changed the title feat(app): onRequest and onResponse global hooks feat(app): onRequest and onAfterResponse global hooks Aug 2, 2023
@pi0 pi0 changed the title feat(app): onRequest and onAfterResponse global hooks feat(app): onRequest and onResponse global hooks Aug 2, 2023
@pi0 pi0 marked this pull request as draft August 2, 2023 07:31
@pi0 pi0 changed the title feat(app): onRequest and onResponse global hooks feat(app): onRequest, onBeforeResponse and onAfterResponse global hooks Aug 2, 2023
@pi0 pi0 marked this pull request as ready for review August 2, 2023 07:39
@pi0 pi0 merged commit c266755 into main Aug 2, 2023
6 checks passed
@pi0 pi0 deleted the feat/req-res-hooks branch August 2, 2023 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow hooking into responses
1 participant