feat: describe addServerHandler

This commit is contained in:
Andrey Yolkin 2023-09-03 23:45:38 +03:00
parent aa75b8c320
commit 7e9ff791e7
No known key found for this signature in database
GPG Key ID: 4A2899263001EA49

View File

@ -2029,7 +2029,63 @@ export default defineNuxtModule({
[source code](https://github.com/nuxt/nuxt/blob/main/packages/kit/src/nitro.ts) [source code](https://github.com/nuxt/nuxt/blob/main/packages/kit/src/nitro.ts)
### `addServerHandler (handler)` ### `addServerHandler`
Adds a nitro server handler.
#### Type
```ts
function addServerHandler (handler: NitroEventHandler): void
export interface NitroEventHandler {
handler: string;
route?: string;
middleware?: boolean;
lazy?: boolean;
method?: string;
}
```
#### Parameters
##### `handler`
**Type**: `NitroEventHandler`
**Required**: `true`
A handler object with the following properties:
- `handler` (required)
**Type**: `string`
Path to event handler.
- `route` (optional)
**Type**: `string`
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.
### `addDevServerHandler (handler)` ### `addDevServerHandler (handler)`