-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (53 loc) · 1.49 KB
/
index.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
50
51
52
53
54
55
56
57
58
const express = require("express");
const { glob } = require("glob");
const app = express();
const port = process.env.PORT || 3000;
app.get("/", (req, res) => {
const trailingSlash = req.query.s === "1" || false;
const absolute = req.query.a === "1" || false;
const follow = req.query.f === "1" || false;
const nodir = req.query.n === "1" || false;
const dot = req.query.d === "1" || false;
const rootPath = "./static" + (trailingSlash ? "/" : "");
glob("**/**", {
cwd: rootPath,
absolute,
follow,
nodir,
dot,
})
.then((files) => {
const jsonData = JSON.stringify(
{
rootPath,
files: files,
options: { trailingSlash, absolute, follow, nodir, dot },
},
null,
2
);
res.send(`
<html>
<body>
<h2>Legend</h2>
<ul>
<li><strong>s</strong> - trailing slash</li>
<li><strong>a</strong> - absolute path</li>
<li><strong>f</strong> - follow symlinks</li>
<li><strong>n</strong> - no directories</li>
<li><strong>d</strong> - dotfiles</li>
</ul>
<h2>Output</h2>
<pre>${jsonData}</pre>
</body>
</html>
`);
})
.catch((error) => {
console.error("Error fetching files:", error);
res.status(500).send("An error occurred");
});
});
app.listen(port, () => {
console.log(`App listening at http://localhost:${port}`);
});