TurtleIO.prototype.handler = function ( method, route, fn, host ) {
host = host || "all";
if ( this.handlers.all.hosts[host] === undefined ) {
this.host( host );
}
this.handlers[method].routes.push( route );
this.handlers[method].regex.push( new RegExp( "^" + route + "$" ) );
this.handlers[method].hosts[host][route] = fn;
return this;
};
Method handler
Sets a handler
Parameters:
method must be a String.
(HTTP method)
route must be a String.
(RegExp pattern)
fn must be a Function.
(Handler)
host must be a String.
([Optional] Virtual host, default is
all
)Returns an Object
(TurtleIO instance)