diff --git a/html/listeFrigos.html b/html/listeFrigos.html index 69836b2ef84eca8dd207cae095bd13c73ab995ff..0d63488ae309175b4dc1acc66b99cfe873c48541 100644 --- a/html/listeFrigos.html +++ b/html/listeFrigos.html @@ -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 diff --git a/scripts/readJson.js b/scripts/readJson.js new file mode 100644 index 0000000000000000000000000000000000000000..d7a15adaa3aec343835206020e6df57c36213d4d --- /dev/null +++ b/scripts/readJson.js @@ -0,0 +1,6 @@ +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 diff --git a/server.js b/server.js new file mode 100644 index 0000000000000000000000000000000000000000..47ee93f4331d9978842ca181d8c3125ac2e55b9d --- /dev/null +++ b/server.js @@ -0,0 +1,23 @@ +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 diff --git a/src/ressources/frigos.json b/src/ressources/frigos.json index 3c2c13fe89e400d616c7f5bcd1137bc07c1b211e..1868d37b90fb688e58aaae797f8833e593de0951 100644 --- a/src/ressources/frigos.json +++ b/src/ressources/frigos.json @@ -1,4 +1,4 @@ -[ +{"array":[ { "nom": "Frigo Antoine", "addresse": "754 Rue Antoine, Montréal, Québec H4R 3T1", @@ -157,4 +157,4 @@ "repas": [ ] } -] +]}