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
```ts
function addDevServerHandler (handler: NitroEventHandler): void
function addDevServerHandler (handler: NitroDevEventHandler): void
export interface NitroEventHandler {
handler: string;
export interface NitroDevEventHandler {
handler: EventHandler;
route?: string;
middleware?: boolean;
lazy?: boolean;
method?: string;
}
```
@ -130,7 +127,7 @@ A handler object with the following properties:
**Type**: `string`
Path to event handler.
The event handler.
- `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.
- `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
::code-group
@ -168,21 +147,17 @@ export default defineNuxtModule({
const resolver = createResolver(import.meta.url)
addDevServerHandler({
handler: resolver.resolve('./runtime/uptime.get'),
handler: () => {
return {
body: `Response generated at ${new Date().toISOString()}`
}
},
route: '/_handler'
})
}
})
```
```ts [runtime/timer.get.ts]
export default defineEventHandler(() => {
return {
body: `Response generated at ${new Date().toISOString()}`
}
})
```
::
```ts