next-api-middleware
Advanced tools
Comparing version 0.6.0 to 0.7.0-canary.0
@@ -0,5 +1,11 @@ | ||
/// <reference types="node" /> | ||
import type { IncomingMessage, ServerResponse } from "http"; | ||
import type { NextApiHandler, NextApiRequest, NextApiResponse } from "next"; | ||
export interface Middleware { | ||
export interface NextMiddleware { | ||
(req: NextApiRequest, res: NextApiResponse, next: () => Promise<void>): Promise<void>; | ||
} | ||
export interface ExpressMiddleware<Request = IncomingMessage, Response = ServerResponse> { | ||
(req: Request, res: Response, next: (error?: any) => void | Promise<void>): void; | ||
} | ||
export declare type Middleware = NextMiddleware | ExpressMiddleware; | ||
export interface LabeledMiddleware { | ||
@@ -6,0 +12,0 @@ [name: string]: Middleware | Middleware[]; |
@@ -53,3 +53,12 @@ "use strict"; | ||
return async function finalRouteHandler(req, res) { | ||
const execute = ([currentFn, ...remaining]) => currentFn(req, res, async () => remaining.length === 0 ? apiRouteFn(req, res) : execute(remaining)); | ||
const execute = ([currentFn, ...remaining]) => { | ||
return currentFn(req, res, async (err) => { | ||
if (err) { | ||
throw err; | ||
} | ||
return remaining.length === 0 | ||
? apiRouteFn(req, res) | ||
: execute(remaining); | ||
}); | ||
}; | ||
return execute(middlewareFns); | ||
@@ -56,0 +65,0 @@ }; |
{ | ||
"name": "next-api-middleware", | ||
"version": "0.6.0", | ||
"version": "0.7.0-canary.0", | ||
"description": "Middleware solution for Next.js API routes", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:htunnicliff/next-api-middleware.git", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12735
112