Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/webmatze/micro-middleware
a simple helper to add middleware to your zeit/micro service
https://github.com/webmatze/micro-middleware
helper micro middleware
Last synced: 2 months ago
JSON representation
a simple helper to add middleware to your zeit/micro service
- Host: GitHub
- URL: https://github.com/webmatze/micro-middleware
- Owner: webmatze
- Created: 2017-03-02T11:53:15.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-26T13:43:02.000Z (about 6 years ago)
- Last Synced: 2024-09-08T12:39:40.221Z (4 months ago)
- Topics: helper, micro, middleware
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# micro-middleware
> a simple helper to add middleware to your zeit/micro service
This will become a set of simple helpers to create and apply middleware to your microsevices using [Zeit](https://zeit.co/)'s [micro](https://github.com/zeit/micro) framework.
## Install
Install with [npm](https://www.npmjs.com/)
```sh
$ npm i micro-middleware --save-dev
```## Usage
### Create a simple middleware
```js
// require micro-middleware helper
var { applyMiddleware } = require('micro-middleware')// a simple middleware should look like this
const logging = fn => async function process (...args) {
console.log(`log args: ${args}`)
let data = await fn.apply(null, args)
console.log(`log returned data: ${data}`)
return data
}const middleware = [
logging
]// create your micro service
const microService = async (req, res) => {
return "hello world"
}// apply middleware and export
module.exports = applyMiddleware(microService, middleware)```
### Apply existing middleware to your microservice
```js
// require micro-middleware helper
var { applyMiddleware } = require('micro-middleware')// require some middleware for micro
const cors = require('micro-cors')()
const compress = require('micro-compress')
const middleware = [
cors,
compress
]// create your micro service
const microService = async (req, res) => {
return "hello world"
}// apply middleware and export
module.exports = applyMiddleware(microService, middleware)
```## Running tests
Install dev dependencies:
```sh
$ npm i -d && npm test
```## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/webmatze/micro-middleware/issues)
## Author
**Mathias Karstädt**
* [github/webmatze](https://github.com/webmatze)
* [twitter/webmatze](http://twitter.com/webmatze)## License
Copyright © 2017 [Mathias Karstädt](http://mathiaskarstaedt.de/)
Licensed under the MIT license.***
_This file was generated by [readme-generator](https://github.com/jonschlinkert/readme-generator) on March 03, 2017._