Skip to content

nayotta/mta-fission-onion

Repository files navigation

mta-fission-onion

Build and LintNode.js Package

简体中文

Used in fission/node-env , like koajs onion code style middleware module.

Install

$ npm install @nayotta/mta-fission-onion

How to use it ?

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

const onion = new Onion()

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

onion.use(async (ctx, next) => {
	// TODO: deal with data
	// ctx.context -> fission/nodejs express/request object
	const data = 'hello' + ctx.request.body.name
	ctx.status = 200
	ctx.body = {
		data
	}
})

// or inject middlewares funcs
onion.inject([async (ctx, next) => {
	// do something
	await next()
}, () => {
	// do something
	await next()
}])

module.export = onion.go()