next-middleware-enhancer
Version:
Enhance Next.js middleware with ease
27 lines (21 loc) • 850 B
TypeScript
import { NextRequest } from 'next/server';
import { NextResponse } from 'next/server';
/**
* `createMiddleware` function
* - Supports Next.js `matcher` patterns to apply middleware based on routes
* - Allows multiple middleware functions to execute sequentially
* - Returns `NextResponse.next()` if no matching middleware is found
*/
export declare function createMiddleware(middlewareList: MiddlewareList): {
middleware: (req: NextRequest) => Promise<NextResponse<unknown>>;
config: {
matcher: string[];
};
};
declare type MiddlewareConfig = {
matcher: string;
handler: MiddlewareFunction | MiddlewareFunction[];
};
declare type MiddlewareFunction = (req: NextRequest) => NextResponse | void | Promise<NextResponse | void>;
declare type MiddlewareList = MiddlewareConfig[];
export { }