-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (25 loc) · 752 Bytes
/
Copy pathindex.js
File metadata and controls
32 lines (25 loc) · 752 Bytes
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
// index.js
const express = require("express");
const fs = require("fs");
const path = require("path");
const app = express();
const PORT = 3000;
const PUBLIC_DIR = path.join(__dirname, "public");
app.use("/public", express.static(PUBLIC_DIR));
// Updated filter: png, jpg, jpeg
app.get("/images", (req, res) => {
const files = fs.readdirSync(PUBLIC_DIR)
.filter(f =>
f.toLowerCase().endsWith(".png") ||
f.toLowerCase().endsWith(".jpg") ||
f.toLowerCase().endsWith(".jpeg")||
f.toLowerCase().endsWith(".webp")
);
res.json(files);
});
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "index.html"));
});
app.listen(PORT, () => {
console.log(`Gallery running at http://localhost:${PORT}`);
});