-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (29 loc) · 991 Bytes
/
server.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
// Keep this file in MagicMirror root directory.
const cors = require("cors");
const app = express();
app.use(cors());
// Define a route to serve the actual files
app.use("/files", express.static(__dirname + "/modules/MMM-MyVideoPlayer/public"));
// Define the file list route
app.get("/fileList/:folder", (req, res) => {
const folder = req.params.folder;
const allowedFolders = ["webms", "gifs", "mp4s"];
// Check if the requested folder is allowed
if (!allowedFolders.includes(folder)) {
res.status(404).json({ error: "Invalid folder" });
return;
}
const fs = require("fs");
const path = `./modules/MMM-MyVideoPlayer/public/${folder}`;
// Ensure the folder exists
if (!fs.existsSync(path)) {
res.status(404).json({ error: "Folder not found" });
return;
}
const fileList = fs.readdirSync(path);
res.json(fileList);
});
const port = 3001; // Adjust as needed
app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});