-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.js
executable file
·49 lines (41 loc) · 1.46 KB
/
router.js
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
const fs = require('fs'),
w = require('./words'),
c = require('./constants'),
router = {};
router[w.noUserCheck] = {};
router[w.files] = {};
module.exports = router;
function loadFiles(path, module, force) {
try {
const files = fs.readdirSync(path);
for (let f of files) {
if (fs.lstatSync(path + f).isDirectory()) {
loadFiles(path + f + "/", module, force);
} else {
const data = fs.readFileSync(path + f);
if (module) {
const code = data.toString().toLowerCase().replace(/\n/gi, '').replace(/ /gi, '');
if (code.includes('router=require')) {
require('./' + path + f);
}
} else {
if (f === "index.html" && path.includes("unstable")) f = "unstable.html";
if (!router[w.files][f]) {
if (c.cache) router[w.files][f] = data;
else router[w.files][f] = () => fs.readFileSync(path + f);
}
}
}
}
} catch (e) {
}
}
loadFiles('services/', true);
const index = c.__dirname + '/public/index.html';
function reload() {
router[w.files] = {};
router[w.files]['index.html'] = !c.cache ? () => fs.readFileSync(index) : fs.readFileSync(index);
loadFiles('public/', false);
}
fs.watchFile(index, {interval: 1000}, () => reload());
reload();