@rxpm/vsfm
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Middleware composition utility

Compose middleware for Vercel Serverless Function.

Installation

$ npm install @rxpm/vsfm

API

Compose list of middleware to get root middeware

compose(handler1, handler2, ..., handlerN)

Example

Using multiple middlewares and single handler

const middleware1: AppMiddleware = (req, res, next) => {
   console.log("executing middleware 1")
   next()
}

const middleware2: AppMiddleware = (req, res, next) => {
   console.log("executing async middleware 2")
   return new Promise(() => {
      setTimeout(() => {
         next()
      }, 3000)
   })
}

const handler: AppHandler = (req, res) => {
   console.log("executing handler")
   res.send("Done")
}

compose(middleware1, middleware2, handler)

Package Sidebar

Install

npm i @rxpm/vsfm

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

3.4 kB

Total Files

7

Last publish

Collaborators

  • rxpm