mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-16 13:48:13 +00:00
docs: document nitro hooks (#7782)
Co-authored-by: Daniel Roe <daniel@roe.dev> Co-authored-by: Damian Głowala <48835293+DamianGlowala@users.noreply.github.com>
This commit is contained in:
parent
c0e99c7273
commit
76f463298e
@ -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('<hr>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).
|
||||
::
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user