neg4n / next-api-compose

🧬 Simple, dependency free, error aware and powerful utility to compose chain of multiple middleware into one Next.js API Route.

Home Page:https://www.npmjs.com/package/next-api-compose

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: allow adding another middleware array optional param, to be executed at the end of the chain

Korayem opened this issue · comments

Suggestion:

import { compose } from 'next-api-compose'

export default compose([preWithBar, preWithFoo], [postWithBar, postWithFoo], (request, response) => {
  const { foo, bar } = request
  response.status(200).json({ foo, bar })
})

Some of the reasons:

  • Logging
  • APM performance tracing
  • fetch.waitUntil() to trigger custom business logic (purge/refresh cache, CRUD events)
  • Analytics
  • HTTP Edge Cache storage of the response body