test
This commit is contained in:
10
dist/router.js
vendored
10
dist/router.js
vendored
@@ -9,19 +9,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
};
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import Tpl from "./template.js";
|
||||
export default class Router {
|
||||
constructor() {
|
||||
this.routes = [];
|
||||
this.mimes = new Map();
|
||||
}
|
||||
importRoutesFromPath(p_1) {
|
||||
return __awaiter(this, arguments, void 0, function* (p, tpl = false) {
|
||||
importRoutesFromPath(p) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const dirEntries = yield fs.promises.readdir(path.resolve() + '/' + p, { withFileTypes: true });
|
||||
for (const tmp of dirEntries) {
|
||||
if (tmp.isFile() && (tmp.name.endsWith(".mjs") || tmp.name.endsWith(".js"))) {
|
||||
const routeModule = (yield import(`${path.resolve()}/${p}/${tmp.name}`)).default;
|
||||
this.use(routeModule(this, tpl));
|
||||
this.use(routeModule(this));
|
||||
}
|
||||
else if (tmp.isDirectory()) {
|
||||
yield this.importRoutesFromPath(p + '/' + tmp.name);
|
||||
@@ -75,9 +74,6 @@ export default class Router {
|
||||
this.routes = [...this.routes, ...obj.routes];
|
||||
this.sortRoutes();
|
||||
}
|
||||
if (obj instanceof Tpl) {
|
||||
this.tpl = obj;
|
||||
}
|
||||
}
|
||||
get(path, ...callback) {
|
||||
this.registerRoute(path, "get", callback);
|
||||
|
||||
Reference in New Issue
Block a user