add more methods

This commit is contained in:
Flummi 2022-03-24 17:17:55 +01:00
parent 0feab31d7f
commit c3e9a3ab00
2 changed files with 37 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{
"name": "flummpress",
"version": "2.0.1",
"version": "2.0.2",
"description": "Express für arme",
"main": "src/index.mjs",
"repository": {

View File

@ -26,6 +26,10 @@ export default class Router {
const methods = {
get: this.get.bind(this),
post: this.post.bind(this),
head: this.head.bind(this),
put: this.put.bind(this),
delete: this.delete.bind(this),
patch: this.patch.bind(this),
};
const target = {
path: new RegExp(path),
@ -69,6 +73,38 @@ export default class Router {
return this;
};
head(path, ...args) {
if(args.length === 1)
this.registerRoute(path, args[0], "head");
else
this.registerRoute(path, args[1], "head", args[0]);
return this;
};
put(path, ...args) {
if(args.length === 1)
this.registerRoute(path, args[0], "put");
else
this.registerRoute(path, args[1], "put", args[0]);
return this;
};
delete(path, ...args) {
if(args.length === 1)
this.registerRoute(path, args[0], "delete");
else
this.registerRoute(path, args[1], "delete", args[0]);
return this;
};
patch(path, ...args) {
if(args.length === 1)
this.registerRoute(path, args[0], "patch");
else
this.registerRoute(path, args[1], "patch", args[0]);
return this;
};
registerRoute(path, cb, method, middleware) {
if(!this.routes.has(path))
this.routes.set(path, {});