2023-12-07 01:28:39 +01:00
|
|
|
import fs from 'fs';
|
2023-12-06 19:11:14 +01:00
|
|
|
const pagesPath = "./src/html/pages/";
|
|
|
|
|
2023-12-07 01:28:39 +01:00
|
|
|
async function deployHandler() {
|
2023-12-06 19:11:14 +01:00
|
|
|
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) {
|
2023-12-07 01:28:39 +01:00
|
|
|
const { default: page } = await import(`.${pagesPath}${category}/${file}`);
|
2023-12-06 19:11:14 +01:00
|
|
|
global.handler[page.type][page.path] = page;
|
|
|
|
console.log(
|
|
|
|
`\x1b[32mChargement de POST: ${page.path} !\x1b[0m`,
|
|
|
|
);
|
|
|
|
numberOfPages++;
|
|
|
|
console.log(numberOfPages + " pages chargées ! ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-07 01:28:39 +01:00
|
|
|
export { deployHandler };
|