router, api and stuff

This commit is contained in:
Flummi
2019-04-25 18:00:47 +00:00
parent 54ea970a3e
commit fb633ba64f
8 changed files with 145 additions and 67 deletions

22
src/inc/router.mjs Normal file
View File

@@ -0,0 +1,22 @@
class Router {
constructor() {
this.routes = new Map();
};
route(method, args) {
this.routes.set(args[0], { method: method, f: args[1] });
console.info("route set", method, args[0]);
};
get() {
this.route("GET", arguments);
};
post() {
this.route("POST", arguments);
};
};
const router = new Router();
export default router;
export const routes = router.routes;
Map.prototype.getRegex = function(path, method, tmp) {
return (!(tmp = [...this.entries()].filter(r => r[0].exec(path) && r[1].method.includes(method))[0])) ? false : tmp[1].f;
};