-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserveur3.js
More file actions
45 lines (42 loc) · 1.27 KB
/
Copy pathserveur3.js
File metadata and controls
45 lines (42 loc) · 1.27 KB
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
43
44
45
const http = require('http');
const fs = require('fs');
const serveur = http.createServer((req, res) => {
fs.readFile('message.txt', 'utf-8', (err, data) => {
if (err) {
res.writeHead(500, { 'Content-Type': 'text/html; charset=utf-8' });
res.end(`
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Erreur serveur</title>
</head>
<body>
<h1>Erreur 500 - Problème interne du serveur</h1>
<p>Impossible de lire le fichier demandé.</p>
<footer>omar</footer>
</body>
</html>
`);
} else {
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
res.end(`
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Message du serveur</title>
</head>
<body>
<h1>Bienvenue sur mon serveur</h1>
<p>${data}</p>
<footer>omar</footer>
</body>
</html>
`);
}
});
});
serveur.listen(8080, () => {
console.log('Serveur en cours d’exécution sur http://localhost:8080');
});