1.0.0 • Published 6 years ago

bragg-wrap-response v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

bragg-wrap-response Build Status

Wraps any result in the body in an extra object on the bragg context

Adds a date to the body in the response bragg context

Install

$ npm install --save bragg-wrap-response

Usage

const bragg = require('bragg');
const wrapResponse = require('bragg-wrap-response');

const app = bragg();

app.use(ctx => {
	ctx.body = {
		foo: 'bar',
		unicorn: 'rainbow',
		user: {
			name: 'Hello',
			password: 'world'
		}
	};
});

app.use(wrapResponse());

app.use(ctx => {
	console.log(ctx.body);
	//=> { date: 2018-03-23T20:50:28.373Z, result: { foo: 'bar', unicorn: 'rainbow', user: { name: 'Hello', password: 'world' } }}
});

exports.handler = app.listen();

API

wrapResponse({options})

Returns a bragg middleware function.

options

Type: object Default: {date: true', key: 'data'}

Related

  • bragg - AWS λ web framework

License

MIT © Bart Callant