createMiddleware
createMiddleware composes middleware for handling requests and responses. It takes an array of H3 middleware.
Import
import { createMiddleware } from "@solidjs/start/middleware";Type
function createMiddleware(args: Middleware[]): Middleware[];Parameters
args
- Type:
Middleware[] - Required: Yes
An array of H3 middleware. To run logic before the response, await next() inside the middleware.
Return value
- Type:
Middleware[]
Returns the composed middleware array.
Behavior
- Each middleware receives the event and a
nextfunction. - A returned
Responseends the chain. - The object form with
onRequestandonBeforeResponsestill works but is deprecated.
Examples
Basic usage
import { createMiddleware } from "@solidjs/start/middleware";
export default createMiddleware([ async (event, next) => { const response = await next(); if (response instanceof Response) return response; return new Response("Not found", { status: 404 }); },]);