Yet Another Plugin Server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

46 lines
1.2 KiB

var plugin = function(){};
plugin.prototype.on = function(event, handler){
if(event == "not-found" || event == "404"){
this.notFound = handler;
} else if(event == "setup"){
this.setup = this.setup || [];
this.setup.push(handler);
} else{
throw new Error("YAPS, cannot add handler for unknown event: " + event);
}
};
plugin.prototype.addRoute = function(method, route, handler){
this.routes = this.routes || {};
method = method.toUpperCase();
this.routes[method] = this.routes[method] || {};
this.routes[method][route] = this.routes[method][route] || [];
this.routes[method][route].push(handler);
};
plugin.prototype.GET = function(route, handler){
this.addRoute("GET", route, handler);
};
plugin.prototype.POST = function(route, handler){
this.addRoute("POST", route, handler);
};
plugin.prototype.PUT = function(route, handler){
this.addRoute("PUT", route, handler);
};
plugin.prototype.HEAD = function(route, handler){
this.addRoute("HEAD", route, handler);
};
plugin.prototype.DELETE = function(route, handler){
this.addRoute("DELETE", route, handler);
};
plugin.prototype.PATCH = function(route, handler){
this.addRoute("PATCH", route, handler);
};
module.exports = plugin;