-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
57 lines (47 loc) · 1.5 KB
/
main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const http = require("http")
const port = 8080
const httpStatus = require("http-status-codes")
const server = http.createServer()
const fs = require("fs")
const route = {
"/" : "/View/index.html"
}
server = http.createServer( (req, res) => {
res.writeHead(httpStatus.OK, {
"Content-Type": "text/html"
})
if (route[req.url]) {
fs.readFile([req.url], (err, data) => {
res.end(data);
})
}else{
res.end("<h1>Page note Found !</h1>")
}
})
server.listen(port, () => {
console.log(`server running at http://localhost:${port}`);
})
// //cet objet permettra d'afficher les data sous forme jSon
// const getJSon = (obj) => {
// return JSON.stringify(obj, null, 3)
// }
// server
// .on("request", (req, res) => { //si une requete arv
// let body = [] //si c'est post on recupere le corps de la requete dans body
// req.on('data', (data) => {
// body.push(data) //On insere les donnees dans la liste
// })
// req.on('end', () => {
// body = Buffer.concat(body).toString() // pour finir on doit concatener les donnees dans body
// console.log(`Request body content ${body}`);
// })
// res.writeHead(httpStatus.OK, {
// "Content-Type": "text/html"
// })
// console.log('Request: ${req.methode}');
// console.log('URL: ${req.url}');
// console.log('Headers: ${getJSon(req.headers)}');
// })
// server.listen(port, () => {
// console.log(`server running at http://localhost:${port}`);
// })