包详细信息

@goa/compose

idiocc36AGPL-3.01.0.0

Compose a single middleware function for Goa out of many.

idio, compose, goa, middleware

自述文件

@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.

  • <kbd>middleware*</kbd> !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.

idiocc © Art Deco™ 2019

更新日志