2013-09-05 17:44:23 +02:00

54 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var caronte = exports,
web = require('./passes/web');
ws = require('./passes/ws');
caronte.createWebProxy = createRightProxy('web');
caronte.createWsProxy = createRightProxy('ws');
/**
* Returns a function that creates the loader for
* either `ws` or `web`'s passes.
*
* Examples:
*
* caronte.createRightProxy('ws')
* // => [Function]
*
* @param {String} Type Either 'ws' or 'web'
* 
* @return {Function} Loader Function that when called returns an iterator for the right passes
*
* @api private
*/
function createRightProxy(type) {
var passes = (type === 'ws') ? ws : web;
return function(options) {
passes = Object.keys(passes).map(function(pass) {
return passes[pass];
});
return function(req, res) {
var self = this,
ev = 'caronte:' + type + ':';
options.ee.emit(ev + 'begin', req, res);
passes.some(function(pass) {
var evnt = ev + pass.name.toLowerCase();
options.ee.emit(evnt + 'begin', req, res);
var val = pass(req, res, options);
options.ee.emit(evnt + 'end');
return val;
});
options.ee.emit(ev + 'end');
};
};
}