@nuxt/docs-nightly 4.6.0-29802745.63ea7d9e → 4.6.0-29803063.d6c7d394
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -19,6 +19,10 @@ The first two kinds of route middleware can be defined in [`definePageMeta`](/do
|
|
|
19
19
|
Name of middleware are normalized to kebab-case: `myMiddleware` becomes `my-middleware`.
|
|
20
20
|
::
|
|
21
21
|
|
|
22
|
+
::note
|
|
23
|
+
Only files at the top level of the directory (or index files within any subdirectories) are registered. An index file takes its name from the folder that contains it: `middleware/auth/index.ts` is registered as `auth`.
|
|
24
|
+
::
|
|
25
|
+
|
|
22
26
|
::note
|
|
23
27
|
Route middleware run within the Vue part of your Nuxt app. Despite the similar name, they are completely different from [server middleware](/docs/4.x/directory-structure/server#server-middleware), which are run in the Nitro server part of your app.
|
|
24
28
|
::
|
package/4.api/5.kit/12.nitro.md
CHANGED
|
@@ -8,7 +8,7 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
Nitro is an open source TypeScript framework to build ultra-fast web servers. Nuxt uses Nitro as its server engine. You can use `useNitro` to access the Nitro instance, `addServerHandler` to add a server handler, `addDevServerHandler` to add a server handler to be used only in development mode, `addServerPlugin` to add a plugin to extend Nitro's runtime behavior, and `addPrerenderRoutes` to add routes to be prerendered by Nitro.
|
|
11
|
+
Nitro is an open source TypeScript framework to build ultra-fast web servers. Nuxt uses Nitro as its server engine. You can use `useNitro` to access the Nitro instance (or `tryUseNitro` if your module should also work without Nitro), `addServerHandler` to add a server handler, `addDevServerHandler` to add a server handler to be used only in development mode, `addServerPlugin` to add a plugin to extend Nitro's runtime behavior, and `addPrerenderRoutes` to add routes to be prerendered by Nitro.
|
|
12
12
|
|
|
13
13
|
## `addServerHandler`
|
|
14
14
|
|
|
@@ -189,6 +189,40 @@ export default defineNuxtModule({
|
|
|
189
189
|
function useNitro (): Nitro
|
|
190
190
|
```
|
|
191
191
|
|
|
192
|
+
## `tryUseNitro`
|
|
193
|
+
|
|
194
|
+
Returns the Nitro instance, or `undefined` when there is none.
|
|
195
|
+
|
|
196
|
+
There is no Nitro instance before the `ready` hook has run, and none at all when the
|
|
197
|
+
configured [`server.builder`](/docs/api/nuxt-config#builder-1) does not use Nitro, such as a
|
|
198
|
+
builder that outputs a client-only SPA. Use this rather than `useNitro()` for anything that
|
|
199
|
+
should keep working without a server: server routes, route rules and prerendering are all
|
|
200
|
+
absent in that case.
|
|
201
|
+
|
|
202
|
+
### Usage
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
import { defineNuxtModule, tryUseNitro } from '@nuxt/kit'
|
|
206
|
+
|
|
207
|
+
export default defineNuxtModule({
|
|
208
|
+
setup (options, nuxt) {
|
|
209
|
+
nuxt.hook('ready', () => {
|
|
210
|
+
const nitro = tryUseNitro()
|
|
211
|
+
if (!nitro) {
|
|
212
|
+
// no server: skip anything that would only run there
|
|
213
|
+
return
|
|
214
|
+
}
|
|
215
|
+
})
|
|
216
|
+
},
|
|
217
|
+
})
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Type
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
function tryUseNitro (): Nitro | undefined
|
|
224
|
+
```
|
|
225
|
+
|
|
192
226
|
## `addServerPlugin`
|
|
193
227
|
|
|
194
228
|
Add plugin to extend Nitro's runtime behavior.
|
package/4.api/6.nuxt-config.md
CHANGED
|
@@ -1317,6 +1317,8 @@ Specify the server builder to use for bundling the server part of your applicati
|
|
|
1317
1317
|
|
|
1318
1318
|
By default, Nuxt uses `@nuxt/nitro-server`, which provides standalone Nitro integration. This architecture allows for different Nitro integration patterns, such as using Nitro as a Vite plugin (with the Vite Environment API).
|
|
1319
1319
|
|
|
1320
|
+
`"nitro"` and `"vite"` are shorthands for `@nuxt/nitro-server` and `@nuxt/vite-server`. The latter is experimental and implemented with Vite alone: it builds the client and ships no server of its own, so with `ssr: false` it produces a static SPA. With SSR enabled the server environment is still built, but running it is left to a Vite plugin that brings its own target or to a custom server. Server routes, route rules and prerendering are unavailable, and modules that need a server will not work.
|
|
1321
|
+
|
|
1320
1322
|
- **Type**: `string | { bundle: (nuxt: Nuxt) => Promise<void> }`
|
|
1321
1323
|
- **Default:** `"@nuxt/nitro-server"`
|
|
1322
1324
|
|