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's micro framework.
Install with npm
$ npm i micro-middleware --save-dev
// 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)
// 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)
Install dev dependencies:
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Mathias Karstädt
Copyright © 2017 Mathias Karstädt Licensed under the MIT license.
This file was generated by readme-generator on March 03, 2017.