From cd36848829db0b5228f9532a10bb15577eb7cff9 Mon Sep 17 00:00:00 2001 From: joel Date: Sat, 25 Dec 2021 19:24:51 +0200 Subject: Server updating finished --- init.sh | 24 +++++++++++++++++++++--- server.js | 1 - 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/init.sh b/init.sh index 2af8e9c..1cf40bf 100755 --- a/init.sh +++ b/init.sh @@ -1,6 +1,24 @@ #!/bin/sh -# Put in this dir so that it can execute: +exec 1>>/tmp/slogs +exec 2>>/tmp/slogs +echo | date +echo "Init running" + cd /home/joel + +echo "Removing old packages..." rm -r -f ./FoodJS -git clone "https://github.com/JoelHMikael/FoodJS.git" >> /tmp/test.txt -node ./FoodJS/server.js + +echo "Waiting for connection..." +while [ ! "$(ping 'www.github.com' -c 1)" ] +do + sleep 5 +done + +echo "Cloning new packages..." +# Create a deployment key and save it in the default folder without passphrase to make this work: +git clone "git@github.com:JoelHMikael/FoodJS.git" + +echo "Starting server..." +cd /home/joel/FoodJS +node ./server.js diff --git a/server.js b/server.js index 39c3a38..514d592 100644 --- a/server.js +++ b/server.js @@ -80,7 +80,6 @@ async function buildMain(args) { const path = args["path"]; const query = args["query"]; - console.log(query); const foods = args["foods"]; let index; if (typeof query.index === "string") -- cgit v1.2.3 From b05479c0d40040c52dbd82d36ad6e206acfdc7c6 Mon Sep 17 00:00:00 2001 From: joel Date: Sun, 26 Dec 2021 14:56:41 +0200 Subject: Implemented https --- server.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index 514d592..ca4beea 100644 --- a/server.js +++ b/server.js @@ -1,4 +1,5 @@ -const http = require("http"); +//const http = require("http"); +const https = require("https"); const fs = require("fs"); const url = require("url"); const parse = require("./parse.js"); @@ -17,13 +18,21 @@ async function init() const errorPath = "./404/index.html"; // await for needed things in async - let [shiftCont, classCont, foodsThisWeek, foodsNextWeek] = await Promise.all([ + let [shiftCont, classCont, foodsThisWeek, foodsNextWeek/*, httpsKey, httpsCert*/] = await Promise.all([ openFile("./shifts.txt"), openFile("./classes.txt"), scrape.food(scrape.link(1)), - scrape.food(scrape.link(2)) + scrape.food(scrape.link(2)), + //openFile("../Certificate/key.pem"), + //openFile("../Certificate/cert.pem") ]); + // https options, you need to get a certificate in the file ../Certificate for the server to work + const httpsOpts = { + key: fs.readFileSync("../Certificate/key.pem"),//httpsKey, + cert: fs.readFileSync("../Certificate/cert.pem")//httpsCert + }; + // get the food shift "database" shiftCont = shiftCont.toString("utf-8").replaceAll("\r", ""); // \r because of the \r\n newline on windows which creates problems classCont = classCont.toString("utf-8").replaceAll("\r", ""); @@ -59,7 +68,7 @@ async function init() } // start server - http.createServer(server).listen(8080); + https.createServer(httpsOpts, server).listen(8080); } -- cgit v1.2.3 From 8f711465194f6779271825bdb2413658880f4c18 Mon Sep 17 00:00:00 2001 From: joel Date: Sun, 26 Dec 2021 17:02:12 +0200 Subject: Fixed bug in day validation & food searching --- server.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index ca4beea..f2752e4 100644 --- a/server.js +++ b/server.js @@ -87,6 +87,7 @@ function openFile(path) async function buildMain(args) { + // get the passed arguments const path = args["path"]; const query = args["query"]; const foods = args["foods"]; @@ -97,14 +98,18 @@ async function buildMain(args) const data = await openFile(path); let data_string = data.toString("utf-8"); + // here are the things to replace in the html page let res = {}; + // get valid day const d = new Date(); let day = d.getDay(); - const actualDay = day; - day = +((day === 0) || (day === 6)) + (+(!(day === 0) && !(day === 6)) * day); - if ((typeof query.day === "string") && (parseInt(query.day).toString() === query.day) && (!isNaN(parseInt(query.day))) && (parseInt(query.day) > 0) && (parseInt(query.day) < 7)) + let actualDay = day; + day = +((day === 0) || (day === 6)) + (+(!(day === 0) && !(day === 6)) * day); // clamp the day between monday (1) and friday (5) (inclusive) + // make the day the passed day instead if the passed day is valid + if ((typeof query.day === "string") && (parseInt(query.day).toString() === query.day) && (!isNaN(parseInt(query.day))) && (parseInt(query.day) > 0) && (parseInt(query.day) < 6)) day = parseInt(query.day); + // set the day selected (must be done manually with this replacement system) data_string = data_string.replace(`