Skip to content

Latest commit

 

History

History
54 lines (42 loc) · 1.29 KB

README.cn.md

File metadata and controls

54 lines (42 loc) · 1.29 KB

mta-fission-onion

Build and LintNode.js Package

EN

fission/node-env 内使用的,仿 koajs 风格洋葱式中间件处理模块.

安装

$ npm install @nayotta/mta-fission-onion

使用

// fission function js file
const { Onion } = require('@nayotta/mta-fission-onion')

const onion = new Onion()

onion.use(async (ctx, next) => {
	// TODO: 权限验证
	const authPass = true
	if (!authPass) {
		ctx.status = 401
		ctx.body = 'unauthrization'
		return
	}
	await next()
})

onion.use(async (ctx, next) => {
	// TODO: 处理数据
	// ctx.request即为fission/nodejs提供的express/request对象
	const data = 'hello' + ctx.request.body.name
	ctx.status = 200
	ctx.body = {
		data
	}
})

// 或者批量注入中间件函数
onion.inject([async (ctx, next) => {
	// do something
	await next()
}, () => {
	// do something
	await next()
}])

module.export = onion.go()