(function(){
var compilePath, σ, guard, respond, i$, ref$, len$, m;
compilePath = require('./compiler').compilePath;
σ = require('highland');
guard = function(cond){
if (cond) {
return σ([null]);
} else {
return σ([]);
}
};
module.exports = respond = curry$(function(method, path, responder){
var lower, extract;
lower = method.toLowerCase();
extract = compilePath(path);
return function(request){
return guard(lower === request.method.toLowerCase()).flatMap(function(){
return extract(request.url).flatMap(function(params){
return responder((request.params = params, request.route = path, request));
});
});
};
});
for (i$ = 0, len$ = (ref$ = ['get', 'post', 'put', 'delete', 'patch', 'options', 'head', 'trace', 'connect']).length; i$ < len$; ++i$) {
m = ref$[i$];
module.exports[m] = respond(m);
}
/* istanbul ignore next */
function curry$(f, bound){
var context,
_curry = function(args) {
return f.length > 1 ? function(){
var params = args ? args.concat() : [];
context = bound ? context || this : this;
return params.push.apply(params, arguments) <
f.length && arguments.length ?
_curry.call(context, params) : f.apply(context, params);
} : f;
};
return _curry();
}
}).call(this);
|