docs: fix addDevServerHandler API (#25233)

This commit is contained in:
Julien Huang 2024-01-16 16:57:49 +01:00 committed by GitHub
parent 986786a4a9
commit 18d279336d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -105,14 +105,11 @@ Adds a nitro server handler to be used only in development mode. This handler wi
### Type ### Type
```ts ```ts
function addDevServerHandler (handler: NitroEventHandler): void function addDevServerHandler (handler: NitroDevEventHandler): void
export interface NitroEventHandler { export interface NitroDevEventHandler {
handler: string; handler: EventHandler;
route?: string; route?: string;
middleware?: boolean;
lazy?: boolean;
method?: string;
} }
``` ```
@ -130,7 +127,7 @@ A handler object with the following properties:
**Type**: `string` **Type**: `string`
Path to event handler. The event handler.
- `route` (optional) - `route` (optional)
@ -138,24 +135,6 @@ A handler object with the following properties:
Path prefix or route. If an empty string used, will be used as a middleware. Path prefix or route. If an empty string used, will be used as a middleware.
- `middleware` (optional)
**Type**: `boolean`
Specifies this is a middleware handler. Middleware are called on every route and should normally return nothing to pass to the next handlers.
- `lazy` (optional)
**Type**: `boolean`
Use lazy loading to import handler.
- `method` (optional)
**Type**: `string`
Router method matcher.
### Examples ### Examples
::code-group ::code-group
@ -168,18 +147,14 @@ export default defineNuxtModule({
const resolver = createResolver(import.meta.url) const resolver = createResolver(import.meta.url)
addDevServerHandler({ addDevServerHandler({
handler: resolver.resolve('./runtime/uptime.get'), handler: () => {
route: '/_handler'
})
}
})
```
```ts [runtime/timer.get.ts]
export default defineEventHandler(() => {
return { return {
body: `Response generated at ${new Date().toISOString()}` body: `Response generated at ${new Date().toISOString()}`
} }
},
route: '/_handler'
})
}
}) })
``` ```