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

docs: document nitro hooks #7782

Merged
merged 7 commits into from Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)