2022-04-04 08:21:30 +00:00
|
|
|
import type { Middleware } from 'h3'
|
2022-05-06 13:31:52 +00:00
|
|
|
import type { NitroEventHandler, NitroDevEventHandler } from 'nitropack'
|
2021-11-21 16:14:46 +00:00
|
|
|
import { useNuxt } from './context'
|
|
|
|
|
2022-05-06 13:31:52 +00:00
|
|
|
export interface LegacyServerMiddleware {
|
2022-04-07 11:32:28 +00:00
|
|
|
route?: string,
|
2022-05-06 13:31:52 +00:00
|
|
|
path?: string,
|
|
|
|
handle?: Middleware | string
|
2022-04-04 08:21:30 +00:00
|
|
|
handler: Middleware | string
|
|
|
|
}
|
|
|
|
|
2022-05-06 13:31:52 +00:00
|
|
|
/**
|
|
|
|
* Adds a new server middleware to the end of the server middleware array.
|
|
|
|
*
|
|
|
|
* @deprecated Use addServerHandler instead
|
|
|
|
*/
|
|
|
|
export function addServerMiddleware (middleware: LegacyServerMiddleware) {
|
2021-11-21 16:14:46 +00:00
|
|
|
useNuxt().options.serverMiddleware.push(middleware)
|
|
|
|
}
|
2022-05-06 13:31:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a nitro server handler
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export function addServerHandler (handler: NitroEventHandler) {
|
|
|
|
useNuxt().options.serverHandlers.push(handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a nitro server handler for development-only
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export function addDevServerHandler (handler: NitroDevEventHandler) {
|
|
|
|
useNuxt().options.devServerHandlers.push(handler)
|
|
|
|
}
|