forked from nuxt/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nuxt, kit): add shortcuts to register custom server handlers (nu…
- Loading branch information
Showing
6 changed files
with
59 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,35 @@ | ||
import type { Middleware } from 'h3' | ||
import type { NitroEventHandler, NitroDevEventHandler } from 'nitropack' | ||
import { useNuxt } from './context' | ||
|
||
export interface ServerMiddleware { | ||
export interface LegacyServerMiddleware { | ||
route?: string, | ||
path?: string, | ||
handle?: Middleware | string | ||
handler: Middleware | string | ||
} | ||
|
||
/** Adds a new server middleware to the end of the server middleware array. */ | ||
export function addServerMiddleware (middleware: ServerMiddleware) { | ||
/** | ||
* Adds a new server middleware to the end of the server middleware array. | ||
* | ||
* @deprecated Use addServerHandler instead | ||
*/ | ||
export function addServerMiddleware (middleware: LegacyServerMiddleware) { | ||
useNuxt().options.serverMiddleware.push(middleware) | ||
} | ||
|
||
/** | ||
* 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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters