Skip to content
Snippets Groups Projects
Commit a0f5e243 authored by Jimmy Bell's avatar Jimmy Bell
Browse files

Ajout du serveur, du script readjson fonctionnel et fuck david

parent 318e83cb
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,7 @@ body{
<meta charset="UTF-8">
<title>Liste des frigos</title>
</head>
<body>
<body id="listeFrigo">
<div class="fridgeOutline">
<span class="bold">
LIRE FRIGO
......@@ -33,4 +33,9 @@ body{
</body>
<script src="../scripts/readJson.js">
var obj = httpGetJson();
document.getElementById("listeFrigo").innerHTML=
</script>
</html>
\ No newline at end of file
function httpGetJson() {
var xmlHttpRequestLocal = new XMLHttpRequest();
xmlHttpRequestLocal.open("GET", "http://127.0.0.1:3000/", false);
xmlHttpRequestLocal.send(null);
return JSON.parse(xmlHttpRequestLocal.responseText);
}
\ No newline at end of file
const http = require('http');
let fs = require('fs');
let json = JSON.parse(fs.readFileSync('src/ressources/frigos.json'));
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.setHeader("Access-Control-Allow-Origin", "*");
if(req.method === 'GET'){
console.log("GET")
res.end(JSON.stringify(json))
}
res.statusCode = 405;
res.end()
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
\ No newline at end of file
[
{"array":[
{
"nom": "Frigo Antoine",
"addresse": "754 Rue Antoine, Montréal, Québec H4R 3T1",
......@@ -157,4 +157,4 @@
"repas": [
]
}
]
]}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment