Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
docs: document nitro hooks (#7782)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Roe <daniel@roe.dev>
Co-authored-by: Damian Głowala <48835293+DamianGlowala@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 26, 2022
1 parent c0e99c7 commit 76f4632
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/content/2.guide/4.going-further/2.hooks.md
Expand Up @@ -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).
::
7 changes: 7 additions & 0 deletions docs/content/3.api/4.advanced/1.hooks.md
Expand Up @@ -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)

0 comments on commit 76f4632

Please sign in to comment.