Skip to content

a simple helper to add middleware to your zeit/micro service

Notifications You must be signed in to change notification settings

webmatze/micro-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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's micro framework.

Install

Install with npm

$ npm i micro-middleware --save-dev

Usage

Create a simple middleware

// 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

// 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:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Mathias Karstädt

License

Copyright © 2017 Mathias Karstädt Licensed under the MIT license.


This file was generated by readme-generator on March 03, 2017.

About

a simple helper to add middleware to your zeit/micro service

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published