From c36d22d74275aa7993bbc838c791c287fc520984 Mon Sep 17 00:00:00 2001 From: julien huang Date: Fri, 23 Sep 2022 10:07:36 +0200 Subject: [PATCH 1/7] docs: add nitro hooks docs --- .../2.guide/4.going-further/2.hooks.md | 24 +++++++++++++++++++ docs/content/3.api/4.advanced/1.hooks.md | 7 ++++++ 2 files changed, 31 insertions(+) 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..b11d7cd5a1e 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,27 @@ export default defineNuxtPlugin((nuxtApp) => { ::alert{icon=๐Ÿ‘‰} Learn more about [available lifecycle hooks](/api/advanced/hooks) :: + + +## Nitro Hooks (Runtime) + +These hooks are available for [Nitro Plugins](https://nitro.unjs.io/guide/advanced/plugins) to hook into nitro's runtime behavior. + +### Usage with Server Plugins + +```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..69957d757ef 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 Hooks (runtime, server-side) + +Hook | Arguments | Description | Type +-----------------------|-----------------------|--------------------------------------|------------------ +`render:response` | `response, { event }` | Called before sending the response. | [response](https://github.com/unjs/h3/blob/f6ceb5581043dc4d8b6eab91e9be4531e0c30f8e/src/types.ts#L38), [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) From e61bee6c89b14c4f2dfae5508362a2b7846ba052 Mon Sep 17 00:00:00 2001 From: julien huang Date: Fri, 23 Sep 2022 10:09:36 +0200 Subject: [PATCH 2/7] docs: typo --- docs/content/3.api/4.advanced/1.hooks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/3.api/4.advanced/1.hooks.md b/docs/content/3.api/4.advanced/1.hooks.md index 69957d757ef..ab22f94b40f 100644 --- a/docs/content/3.api/4.advanced/1.hooks.md +++ b/docs/content/3.api/4.advanced/1.hooks.md @@ -31,7 +31,7 @@ Check the [schema source code](https://github.com/nuxt/framework/blob/main/packa # Nitro Hooks (runtime, server-side) -Hook | Arguments | Description | Type +Hook | Arguments | Description | Types -----------------------|-----------------------|--------------------------------------|------------------ `render:response` | `response, { event }` | Called before sending the response. | [response](https://github.com/unjs/h3/blob/f6ceb5581043dc4d8b6eab91e9be4531e0c30f8e/src/types.ts#L38), [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) From 2b22c4b833a567651e375f29dbd8e2ac6db5c44b Mon Sep 17 00:00:00 2001 From: julien huang Date: Fri, 23 Sep 2022 10:11:42 +0200 Subject: [PATCH 3/7] style: lint --- docs/content/2.guide/4.going-further/2.hooks.md | 1 - 1 file changed, 1 deletion(-) 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 b11d7cd5a1e..34bac8def5c 100644 --- a/docs/content/2.guide/4.going-further/2.hooks.md +++ b/docs/content/2.guide/4.going-further/2.hooks.md @@ -46,7 +46,6 @@ export default defineNuxtPlugin((nuxtApp) => { Learn more about [available lifecycle hooks](/api/advanced/hooks) :: - ## Nitro Hooks (Runtime) These hooks are available for [Nitro Plugins](https://nitro.unjs.io/guide/advanced/plugins) to hook into nitro's runtime behavior. From 86c24cdbf897aaba0451de4b6573c27ad2655bd2 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 23 Sep 2022 09:19:55 +0100 Subject: [PATCH 4/7] docs: rename to nitro app hooks --- docs/content/2.guide/4.going-further/2.hooks.md | 6 +++--- docs/content/3.api/4.advanced/1.hooks.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) 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 34bac8def5c..1384c558474 100644 --- a/docs/content/2.guide/4.going-further/2.hooks.md +++ b/docs/content/2.guide/4.going-further/2.hooks.md @@ -46,11 +46,11 @@ export default defineNuxtPlugin((nuxtApp) => { Learn more about [available lifecycle hooks](/api/advanced/hooks) :: -## Nitro Hooks (Runtime) +## 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. +These hooks are available for [Nitro plugins](https://nitro.unjs.io/guide/advanced/plugins) to hook into Nitro's runtime behavior. -### Usage with Server Plugins +### Usage within a Nitro Plugin ```js [~/server/plugins/test.ts] export default defineNitroPlugin((nitroApp) => { diff --git a/docs/content/3.api/4.advanced/1.hooks.md b/docs/content/3.api/4.advanced/1.hooks.md index ab22f94b40f..8eff4f48aea 100644 --- a/docs/content/3.api/4.advanced/1.hooks.md +++ b/docs/content/3.api/4.advanced/1.hooks.md @@ -29,7 +29,7 @@ Check the [schema source code](https://github.com/nuxt/framework/blob/main/packa :NeedContribution -# Nitro Hooks (runtime, server-side) +# Nitro App Hooks (runtime, server-side) Hook | Arguments | Description | Types -----------------------|-----------------------|--------------------------------------|------------------ From 17c61c222d2f7ef015552f4592e802bd68c74ae9 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 23 Sep 2022 09:20:15 +0100 Subject: [PATCH 5/7] docs: lint --- docs/content/2.guide/4.going-further/2.hooks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1384c558474..f90aba892b1 100644 --- a/docs/content/2.guide/4.going-further/2.hooks.md +++ b/docs/content/2.guide/4.going-further/2.hooks.md @@ -66,5 +66,5 @@ export default defineNitroPlugin((nitroApp) => { ``` ::alert{icon=๐Ÿ‘‰} -Learn more about [available nitro lifecycle hooks](/api/advanced/hooks#nitro-hooks-runtime-server-side) +Learn more about [available Nitro lifecycle hooks](/api/advanced/hooks#nitro-hooks-runtime-server-side) :: From 94de710d46fda5b6307da9c2eafd23fc3a934f40 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 23 Sep 2022 09:46:17 +0100 Subject: [PATCH 6/7] docs: fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Damian Gล‚owala <48835293+DamianGlowala@users.noreply.github.com> --- docs/content/2.guide/4.going-further/2.hooks.md | 2 +- docs/content/3.api/4.advanced/1.hooks.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 f90aba892b1..959363311c6 100644 --- a/docs/content/2.guide/4.going-further/2.hooks.md +++ b/docs/content/2.guide/4.going-further/2.hooks.md @@ -66,5 +66,5 @@ export default defineNitroPlugin((nitroApp) => { ``` ::alert{icon=๐Ÿ‘‰} -Learn more about [available Nitro lifecycle hooks](/api/advanced/hooks#nitro-hooks-runtime-server-side) +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 8eff4f48aea..a55c987818b 100644 --- a/docs/content/3.api/4.advanced/1.hooks.md +++ b/docs/content/3.api/4.advanced/1.hooks.md @@ -33,5 +33,5 @@ Check the [schema source code](https://github.com/nuxt/framework/blob/main/packa Hook | Arguments | Description | Types -----------------------|-----------------------|--------------------------------------|------------------ -`render:response` | `response, { event }` | Called before sending the response. | [response](https://github.com/unjs/h3/blob/f6ceb5581043dc4d8b6eab91e9be4531e0c30f8e/src/types.ts#L38), [event](https://github.com/unjs/h3/blob/f6ceb5581043dc4d8b6eab91e9be4531e0c30f8e/src/types.ts#L38) +`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) From ecc32de0924bc5517f1974d0c0b5388191a933e5 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 23 Sep 2022 09:47:07 +0100 Subject: [PATCH 7/7] docs: remove semis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Damian Gล‚owala <48835293+DamianGlowala@users.noreply.github.com> --- docs/content/2.guide/4.going-further/2.hooks.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 959363311c6..636db5e77eb 100644 --- a/docs/content/2.guide/4.going-further/2.hooks.md +++ b/docs/content/2.guide/4.going-further/2.hooks.md @@ -55,14 +55,14 @@ These hooks are available for [Nitro plugins](https://nitro.unjs.io/guide/advanc ```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'); - }); + console.log('render:html', html) + html.bodyAppend.push('
Appended by custom plugin') + }) nitroApp.hooks.hook('render:response', (response, { event }) => { - console.log('render:response', response); - }); -}); + console.log('render:response', response) + }) +}) ``` ::alert{icon=๐Ÿ‘‰}