30 lines
909 B
JavaScript
30 lines
909 B
JavaScript
import fs from 'fs';
|
|
const pagesPath = "./src/html/pages/";
|
|
|
|
async function deployHandler() {
|
|
global.handler = {
|
|
get: {},
|
|
post: {},
|
|
};
|
|
let numberOfPages = 0;
|
|
const PagesCategories = fs
|
|
.readdirSync(pagesPath)
|
|
.filter((file) => !file.includes("."));
|
|
for (const category of PagesCategories) {
|
|
const pageFiles = fs
|
|
.readdirSync(`${pagesPath}${category}`)
|
|
.filter((file) => file.endsWith(".js"));
|
|
for (const file of pageFiles) {
|
|
const { default: page } = await import(`.${pagesPath}${category}/${file}`);
|
|
global.handler[page.type][page.path] = page;
|
|
console.log(
|
|
`\x1b[32mChargement de POST: ${page.path} !\x1b[0m`,
|
|
);
|
|
numberOfPages++;
|
|
console.log(numberOfPages + " pages chargées ! ");
|
|
}
|
|
}
|
|
}
|
|
|
|
export { deployHandler };
|