Skip to content
Million edited this page Aug 29, 2015 · 6 revisions

Welcome to the pomelo-http-plugin wiki!

###How to add filter

CAUTION: You should not call res.end() or res.send() or any other similar methods which ending the http flow if use afterFilter.

//log.js
module.exports = function() {
	return new LogFilter();
}

var LogFilter = function() {
}

LogFilter.prototype.before = function(req, res, next) {
	console.log('[http request]:', req.method, req.url);
	next();
}

LogFilter.prototype.after = function(req, res, next) {
	console.log('[http response]:', req.method, req.url, res.get('resp'));
	next();
}

//testRoute.js
http.get('/test', function(req, res, next) {
	res.set('response', 'success');
	next();
});

//app.js
httpPlugin.filter(require('/path/to/log.js')());
//add the ending after filter
httpPlugin.afterFilter(function(req, res) {
	res.send(res.get('resp'));
});
Clone this wiki locally