Spaces:
Runtime error
Runtime error
Update server.js
Browse files
server.js
CHANGED
@@ -5,24 +5,16 @@ const path = require('path');
|
|
5 |
const app = express();
|
6 |
const PORT = process.env.PORT || 7860;
|
7 |
|
8 |
-
// Serve static files from public folder
|
9 |
app.use(express.static('public'));
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
fs.readdir('./music', (err, files) => {
|
14 |
if (err) {
|
15 |
return res.sendStatus(500);
|
16 |
}
|
17 |
-
res.json(files);
|
18 |
});
|
19 |
});
|
20 |
|
21 |
-
|
22 |
-
app.get('/music/:filename', (req, res) => {
|
23 |
-
const { filename } = req.params;
|
24 |
-
const filepath = path.resolve(__dirname, 'music', filename);
|
25 |
-
res.sendFile(filepath);
|
26 |
-
});
|
27 |
-
|
28 |
-
app.listen(PORT, () => console.log(`Server listening on port ${PORT}`));
|
|
|
5 |
const app = express();
|
6 |
const PORT = process.env.PORT || 7860;
|
7 |
|
|
|
8 |
app.use(express.static('public'));
|
9 |
+
app.use('/music', express.static('music'));
|
10 |
|
11 |
+
app.get('/tracks', (req, res) => {
|
12 |
+
fs.readdir('music', (err, files) => {
|
|
|
13 |
if (err) {
|
14 |
return res.sendStatus(500);
|
15 |
}
|
16 |
+
res.json(files.filter(file => file.endsWith('.mp3')));
|
17 |
});
|
18 |
});
|
19 |
|
20 |
+
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
|
|
|
|
|
|
|
|
|
|
|
|
|
|