aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoelHMikael <53561102+JoelHMikael@users.noreply.github.com>2022-01-18 18:57:10 +0200
committerGitHub <noreply@github.com>2022-01-18 18:57:10 +0200
commitedf044c1e1e0c751229549dd9d14062b230149be (patch)
treead18984d3031ce6bc7ccb549415c58d77672a53f
parentf0d41b4b7ef5faff8fbc84de9175f67746a5a8b3 (diff)
parent8f711465194f6779271825bdb2413658880f4c18 (diff)
downloadLYLLRuoka-edf044c1e1e0c751229549dd9d14062b230149be.tar.gz
LYLLRuoka-edf044c1e1e0c751229549dd9d14062b230149be.zip
Merge branch 'master' into MYSQLDB
-rwxr-xr-xinit.sh24
-rw-r--r--server.js27
2 files changed, 42 insertions, 9 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 e5a3277..1431465 100644
--- a/server.js
+++ b/server.js
@@ -1,12 +1,13 @@
+
const http = require("http");
-//const fs = require("fs");
+const https = require("https");
+const fs = require("fs");
const url = require("url");
const scrape = require("./scrape.js");
const SQL_DBS = require("./database.js");
const DBPARSE = require("./dbparse.js");
const openFile = require("./open.js").file;
const updateDB = require("./update.js");
-const { start } = require("repl");
async function init()
@@ -27,12 +28,20 @@ async function init()
let visitorCount = 0;
// await for needed things in async
- let [foodsThisWeek, foodsNextWeek, dbcredentials] = await Promise.all([
+ let [foodsThisWeek, foodsNextWeek, dbcredentials, httpsKey, httpsCert] = await Promise.all([
scrape.food(scrape.link(1)),
scrape.food(scrape.link(2)),
- openFile("../dblogin.txt")
+ openFile("../dblogin.txt"),
+ 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: httpsKey,
+ cert: httpsCert
+ };
+
// get the MySQL DB connection
const SQLDB = new SQL_DBS.Database(JSON.parse(dbcredentials));
@@ -135,6 +144,7 @@ function replace(s, from, to)
async function buildMain(args)
{
+ // get the passed arguments
const path = args["path"];
const query = args["query"];
const foods = args["foods"];
@@ -143,8 +153,10 @@ 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();
day = (day + +(day === 0) * 7) - 1;
@@ -152,6 +164,7 @@ async function buildMain(args)
day = +(!(day === 5) && !(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) < 5))
day = parseInt(query.day);
+ // set the day selected (must be done manually with this replacement system)
data_string = data_string.replace(`<option value=\"${day}\">`, `<option value=\"${day}\" selected>`);
// get the food shift to res["shift"]
@@ -202,6 +215,8 @@ async function buildMain(args)
data_string = data_string.replace('<div id="shift-result" class="float-block">', '<div id="shift-result" class="float-block" style="display: none;">');
// get the food
+ day += (day === 0) * 7;
+ actualDay += (actualDay === 0) * 7;
let food;
food = foods[ +(day < actualDay) ][day];
if (food !== undefined)
@@ -214,7 +229,7 @@ async function buildMain(args)
res["food-header"] = weekdays[day];
res["food"] = "Päivälle ei löytynyt ruokaa";
}
- res["food-header"] = `Päivän ${res["food-header"]} kouluruoka:`;
+ res["food-header"] = `Kouluruoka ${res["food-header"]}:`;
data_string = build_replace(data_string, res);