Skip to content

Commit

Permalink
feat: call render:response hook for defineRenderHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 8, 2022
1 parent e0ec2b2 commit 8238f38
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/runtime/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { handlers } from '#internal/nitro/virtual/server-handlers'
export interface NitroApp {
h3App: H3App
router: Router
// TODO: Type hooks and allow extending
hooks: Hookable
localCall: ReturnType<typeof createCall>
localFetch: ReturnType<typeof createLocalFetch>
Expand Down
5 changes: 5 additions & 0 deletions src/runtime/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CompatibilityEvent, eventHandler } from 'h3'
import { useNitroApp } from './app'

export interface RenderResponse {
body: string,
Expand All @@ -20,6 +21,10 @@ export function defineRenderHandler (handler: RenderHandler) {

const response = await handler(event)

// Allow hooking and modifying response
const nitroApp = useNitroApp()
await nitroApp.hooks.callHook('render:response', response, { event })

// TODO: Warn if response is already handled

// TODO: Caching support
Expand Down

0 comments on commit 8238f38

Please sign in to comment.