diff --git a/docs/content/2.guide/4.going-further/2.hooks.md b/docs/content/2.guide/4.going-further/2.hooks.md index 05ce029a12c..636db5e77eb 100644 --- a/docs/content/2.guide/4.going-further/2.hooks.md +++ b/docs/content/2.guide/4.going-further/2.hooks.md @@ -45,3 +45,26 @@ export default defineNuxtPlugin((nuxtApp) => { ::alert{icon=👉} Learn more about [available lifecycle hooks](/api/advanced/hooks) :: + +## Nitro App Hooks (Runtime) + +These hooks are available for [Nitro plugins](https://nitro.unjs.io/guide/advanced/plugins) to hook into Nitro's runtime behavior. + +### Usage within a Nitro Plugin + +```js [~/server/plugins/test.ts] +export default defineNitroPlugin((nitroApp) => { + nitroApp.hooks.hook('render:html', (html, { event }) => { + console.log('render:html', html) + html.bodyAppend.push('
Appended by custom plugin') + }) + + nitroApp.hooks.hook('render:response', (response, { event }) => { + console.log('render:response', response) + }) +}) +``` + +::alert{icon=👉} +Learn more about available [Nitro lifecycle hooks](/api/advanced/hooks#nitro-hooks-runtime-server-side). +:: diff --git a/docs/content/3.api/4.advanced/1.hooks.md b/docs/content/3.api/4.advanced/1.hooks.md index 5a086becdaf..a55c987818b 100644 --- a/docs/content/3.api/4.advanced/1.hooks.md +++ b/docs/content/3.api/4.advanced/1.hooks.md @@ -28,3 +28,10 @@ Hook | Arguments | Environment | Description Check the [schema source code](https://github.com/nuxt/framework/blob/main/packages/schema/src/types/hooks.ts#L55) for all available hooks. :NeedContribution + +# Nitro App Hooks (runtime, server-side) + +Hook | Arguments | Description | Types +-----------------------|-----------------------|--------------------------------------|------------------ +`render:response` | `response, { event }` | Called before sending the response. | [response](https://github.com/nuxt/framework/blob/71ef8bd3ff207fd51c2ca18d5a8c7140476780c7/packages/nuxt/src/core/runtime/nitro/renderer.ts#L24), [event](https://github.com/unjs/h3/blob/f6ceb5581043dc4d8b6eab91e9be4531e0c30f8e/src/types.ts#L38) +`render:html` | `html, { event }` | Called before constructing the HTML. | [html](https://github.com/nuxt/framework/blob/71ef8bd3ff207fd51c2ca18d5a8c7140476780c7/packages/nuxt/src/core/runtime/nitro/renderer.ts#L15), [event](https://github.com/unjs/h3/blob/f6ceb5581043dc4d8b6eab91e9be4531e0c30f8e/src/types.ts#L38)