1.0.0 • Published 4 years ago

@goa/compose v1.0.0

Weekly downloads
5
License
AGPL-3.0
Repository
github
Last release
4 years ago

@goa/compose

npm version

@goa/compose is Compose a single middleware function for Goa out of many.

yarn add @goa/compose

Table Of Contents

API

The package is available by importing its default function:

import compose from '@goa/compose'

compose(  middleware: !Array<!Function>,): !Function

Compose a single middleware function for Goa out of many.

  • middleware* !Array<!Function>: The array with the middleware.
import Goa from '@goa/koa'
import rqt from 'rqt'
import compose from '@goa/compose'

const goa = new Goa()

const composed = compose([
  async (ctx, next) => {
    ctx.body = 'hello'
    await next()
  },
  async (ctx) => {
    ctx.body += ' world'
  },
])

goa.use(composed)

goa.listen(async function() {
  const url = `http://127.0.0.1:${this.address().port}`
  const res = await rqt(url)
  console.log(res)
  this.close()
})
hello world

Copyright & License

GNU Affero General Public License v3.0

Original work by dead-horse under MIT license. Copy of the license is not included as not found in the original package.