import routes recursive
This commit is contained in:
parent
2c77caf4f5
commit
431aeda80b
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "flummpress",
|
"name": "flummpress",
|
||||||
"version": "2.0.3",
|
"version": "2.0.4",
|
||||||
"description": "Express für arme",
|
"description": "Express für arme",
|
||||||
"main": "src/index.mjs",
|
"main": "src/index.mjs",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -11,14 +11,11 @@ export default class Router {
|
||||||
};
|
};
|
||||||
|
|
||||||
async importRoutesFromPath(p, tpl = false) {
|
async importRoutesFromPath(p, tpl = false) {
|
||||||
await Promise.all(
|
for(let tmp of await fs.promises.readdir(path.resolve() + '/' + p, { withFileTypes: true }))
|
||||||
fs.readdirSync(path.resolve() + "/" + p)
|
if(tmp.isFile() && tmp.name.endsWith('.mjs'))
|
||||||
.filter(r => r.endsWith(".mjs"))
|
this.use((await import(`${path.resolve()}/${p}/${tmp.name}`)).default(this, tpl));
|
||||||
.map(async r => {
|
else if(tmp.isDirectory())
|
||||||
const tmp = (await import(`${path.resolve()}/${p}/${r}`)).default(this, tpl);
|
await this.importRoutesFromPath(p + '/' + tmp.name);
|
||||||
this.use(tmp);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user