apiref
init-middleware@0.0.1

initMiddleware()  Function

Adapts an Express middleware into an async function suitable for use with Next.js API routes.

This is taken directly from https://github.com/vercel/next.js/blob/canary/examples/api-routes-cors/lib/init-middleware.js

Signature

export declare function initMiddleware<T extends Function>(middleware: T): (req: any, res: any) => Promise<any>;

Parameters

ParameterTypeDescription
middlewareT

The Express middleware instance

(Returns)(req: any, res: any) => Promise<any>

An async function that should be called with (req, res) to execute the middleware