-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
42 lines (35 loc) · 1.08 KB
/
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
40
41
42
const express = require('express');
const fs = require('fs').promises;
const path = require('path');
const app = express();
// Servir les fichiers statiques
app.use('/src', express.static(path.join(__dirname, 'src')));
app.use('/ressources', express.static(path.join(__dirname, 'ressources')));
//app.use('/js', express.static(path.join(__dirname, 'ressources/js')));
app.get('/', async (req, res) => {
try {
const filePath = path.join(__dirname, 'src/map/map.html');
const contenu = await fs.readFile(filePath, 'utf8');
res.send(contenu);
} catch (err) {
console.error(err);
res.status(500).send('Error reading file');
}
});
app.get('/:fichier', async (req, res) => {
const { fichier } = req.params;
if (fichier === "favicon.ico") {
return;
}
const filePath = path.join(__dirname, 'src', fichier);
try {
const contenu = await fs.readFile(filePath, 'utf8');
res.send(contenu);
} catch (err) {
console.error(err);
res.status(404).send('File not found');
}
});
app.listen(3000, () => {
console.log('Server is listening on port 3000');
});