rexfordessilfie / nextwrappers

Reusable, composable middleware-like wrappers for Next.js App Router Route Handlers and Middleware.
MIT License
24 stars 0 forks source link

feat: add pages api wrappers #12

Closed rexfordessilfie closed 1 year ago

rexfordessilfie commented 1 year ago

Overview

This PR pulls in implementation from nextjs-handler-middleware for the pages directory approach to API handlers.

Other

It also solves the problem of not being able to override the any type on NextApiRequest['body'] by introducing a SpecificIntersection type the prefers the more specific type in an intersection with another type.

This allows for middleware like validated to produce a request with a specific body type on the other side of the middleware without having to introduce a new property on the request.