router, api and stuff
This commit is contained in:
22
src/inc/router.mjs
Normal file
22
src/inc/router.mjs
Normal 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;
|
||||
};
|
Reference in New Issue
Block a user