File size: 2,909 Bytes
59485cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
const router = require("express").Router();
const { readdirSync, readFileSync } = require('fs-extra');
const path = require('path');
try {
// ------------------------------------------------------------------------//
// ------------------------/ Fodel public /-------------------------//
// ------------------------------------------------------------------------//
console.log("\x1b[33m%s\x1b[0m", "I am in yellow color");
console.log("%cHere","color:blue;font-size: larger")
var i, j, n = 0;
const srcPath = path.join(__dirname, "/public/");
const hosting = readdirSync(srcPath).filter((file) => file.endsWith(".js"));
for (i of hosting) {
const { index, name } = require(srcPath + i);
router.get(name, index);
n++
console.log(i);
}
// for 'post' folder
const srcPathPost = path.join(__dirname, "/post/");
const hostingPost = readdirSync(srcPathPost).filter((file) => file.endsWith(".js"));
for (j of hostingPost) {
const { index, name } = require(srcPathPost + j);
router.post(name, index);
n++
console.log('post/' + j);
}
router.get('/altp_data', function (req, res) {
const data = JSON.parse(readFileSync('./altp_data.json', "utf-8"));
res.header("Content-Type", 'application/json');
res.send(JSON.stringify(data, null, 4));
});
// ------------------------------------------------------------------------//
// ----------------------------/ Fodel /----------------------------//
// ------------------------------------------------------------------------//
const getDirs = readdirSync(srcPath).filter((file) => !file.endsWith(".js") && !file.endsWith(".json"));
for (const dir of getDirs) {
const fileName = readdirSync(path.join(__dirname, '/public/' + dir + '/')).filter((file) => file.endsWith(".js"));
for (j of fileName) {
const { index, name } = require(path.join(__dirname, '/public/' + dir + '/') + j);
router.get(name, index);
n++
// console.log('\x1b[38;5;220m[ LOADING ] \x1b[33m鈫抃x1b[40m\x1b[1m\x1b[38;5;161m 膼茫 t岷 th脿nh c么ng ' + j);
}
}
// for 'post' folder
const getDirsPost = readdirSync(srcPathPost).filter((file) => !file.endsWith(".js") && !file.endsWith(".json"));
for (const dir of getDirsPost) {
const fileName = readdirSync(path.join(__dirname, '/post/' + dir + '/')).filter((file) => file.endsWith(".js"));
for (j of fileName) {
const { index, name } = require(path.join(__dirname, '/post/' + dir + '/') + j);
router.post(name, index);
n++
console.log('\x1b[38;5;220m[ LOADING ] \x1b[33m鈫抃x1b[38;5;197m 膼茫 t岷 th脿nh c么ng POST/' + j);
}
}
console.log(`\x1b[38;5;220m[ LOADING ] \x1b[33m鈫抃x1b[38;5;197m 膼茫 load th脿nh c么ng ${n} file API`);
} catch (e) { console.log(e); }
// --------------------------> END <------------------------------//
module.exports = router; |