1.0.7 • Published 10 years ago

promise-middleware v1.0.7

Weekly downloads
1
License
MIT
Repository
github
Last release
10 years ago

Promise Middleware

Build Status npm Version License

This module wraps HTTP callback-based middlewares that follow the convention (req, res, next) popularized by frameworks such as Connect and Express, and turns them into promises. This enables them to be used in a generic manner without frameworks, and with flow control features such as async/await.

$ npm install promise-middleware

Usage

import http from 'http'
import middlewareWrapper from 'promise-middleware'
import corsMiddleware from 'cors'

const cors = corsMiddleware()

// ES7 example.
http.createServer(async (request, response) => {
  // The signature of the wrapper function is typically `request`, `response`,
  // and lastly `middleware`, which is a function that typically accepts the
  // arguments `req`, `res`, `next`.
  const middleware = fn => middlewareWrapper(request, response, fn)

  await middleware(cors)

  response.end('Hello world!')
})

.listen(1337)

License

This software is licensed under the MIT License.

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago