smallorange-connect

1.0.1 • Public • Published

CircleCI

Small Orange Connect

It emulates express/restify middlewares execution and returns the results via callback.

Sample

	const Connect = require('smallorange-connect');

	const req = {}; // any req object
	const res = {}; // allow override methods
	const callback = console.log;
	const connect = new Connect(req, res, callback);

	const middlewares = [
		(req, res, next) => {
			req.someAttr = 1;

			next();
		},
		(req, res, next) => {
			req.someAttr = 2;

			next();
		},
		[ // nested middleware
			(req, res, next) => {
				req.someAttr = 2;
				
				res.header('content-type', 'text/html');
				res.status(200);
				res.end(req.someAttr);
			},
		]
	];

	connect.executeHandlers(middlewares);

	// once execute, will log via callback
	{
		headers: {
			'content-type': 'text/html'
		},
		statusCode: 200,
		body: 2
	}

	// or with errors

	const middlewares = [
		(req, res, next) => {
			req.someAttr = 2;

			next('some error');
		}
	];

	connect.executeHandlers(middlewares);

	// once execute, will log via callback
	{
		statusCode: 500,
		message: 'some error'
	}

Readme

Keywords

none

Package Sidebar

Install

npm i smallorange-connect

Weekly Downloads

1

Version

1.0.1

License

ISC

Last publish

Collaborators

  • feliperohde