-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
28 lines (23 loc) · 771 Bytes
/
Copy pathserver.js
File metadata and controls
28 lines (23 loc) · 771 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
const express = require('express');
const fs = require('fs');
const path = require('path');
const app = express();
const port = 3001;
app.use(express.static('./'));
// Serve index.html at the root URL
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
app.get('/images', (req, res) => {
const imagesDir = path.join(__dirname, 'images');
fs.readdir(imagesDir, (err, files) => {
if (err) {
return res.status(500).send('Unable to scan directory');
}
const images = files.filter(file => /\.(jpg|jpeg|png|gif|webp)$/.test(file));
res.json(images);
});
});
app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
});