From 1ddfc8c769ca094c6e0e4763076ec187f7a388ab Mon Sep 17 00:00:00 2001 From: Christopher Hase Date: Tue, 15 Apr 2025 16:28:48 +0200 Subject: [PATCH] add http-server part 9.1 --- backend/broker.ts | 17 ++++++++--------- backend/server.ts | 7 +++++-- frontend/event.ts | 4 ++-- frontend/index.html | 5 +++-- start.sh | 0 5 files changed, 18 insertions(+), 15 deletions(-) mode change 100644 => 100755 start.sh diff --git a/backend/broker.ts b/backend/broker.ts index 391235b..5cbee8d 100644 --- a/backend/broker.ts +++ b/backend/broker.ts @@ -22,7 +22,7 @@ export function executeCommand(): void { exec('iching divine', (error, stdout, stderr) => { - console.log(`Begin`); + console.log(`I-Ching-Broker: \'iching divine\' called`); if (error) { console.error(`Error: ${error.message}`); @@ -39,7 +39,7 @@ export function executeCommand(): void { config = loadConfig(); } */ - console.log(`Send E-Mail`); + console.log(`Horoscope received; sending E-Mail next`); sendEmail(stdout); }); } @@ -75,9 +75,11 @@ async function sendEmail(content: string) { html: html(content) }); - console.log("E-Mail sent: ", info.messageId + "\n"); + console.log("E-Mail sent: ", info.messageId + "\n\n"); } catch (error) { - console.error("Error Sending E-Mail:", error); + console.error("Error Sending E-Mail:", error + "\n\n"); + + console.log("Failed to send horoscope: \n", content + "\n"); } } @@ -119,7 +121,7 @@ function parse(input: string): Node { const changingLines: Node = { type: "ChangingLines"}; currentNode.child = changingLines; currentNode = changingLines; - currentNode.value = line; // + "
"; TODO: try without this
+ currentNode.value = line; } else { currentNode.value = currentNode.value + line + "
"; } @@ -132,13 +134,11 @@ function parse(input: string): Node { function render(node: Node): string { if (node == undefined) { - console.log("Rendering of nodes finished!") + console.log("I-Ching-Broker: Rendering of nodes finished!") return ""; } - console.log("Render node" + node.type); - var outputHTML: string = ""; switch (node.type) { @@ -161,7 +161,6 @@ function render(node: Node): string { case "ChangingLines" : const regex = new RegExp("~", "g"); node.value = node.value?.replace(regex, ""); - //outputHTML = "

" + node.value + "


"; outputHTML = "

" + node.value + "


"; outputHTML = outputHTML + render(node.child!); return outputHTML; diff --git a/backend/server.ts b/backend/server.ts index c045e0e..4a76fc7 100644 --- a/backend/server.ts +++ b/backend/server.ts @@ -8,10 +8,13 @@ const port = 8090; app.use(cors()); app.post('/iching/api/command', (req, res) => { + //TODO no logging from inside this method??? + console.log(`Backend-Server: receiving POST to /iching/api/command`); + executeCommand(); - res.status(200).send('Command executed\n'); + res.status(200).send('Backend-Server: Broker was called\n'); }); app.listen(port, '0.0.0.0', () => { - console.log(`Server läuft auf http://0.0.0.0:${port}`); + console.log(`Backend-Server running on http://0.0.0.0:${port}`); }); diff --git a/frontend/event.ts b/frontend/event.ts index 4a7a778..3430561 100644 --- a/frontend/event.ts +++ b/frontend/event.ts @@ -3,8 +3,8 @@ function handleClick(): void { fetch("/iching/api/command", { method: "POST" }) .then(res => res.text()) - .then(text => console.log("Server sagt:", text)) - .catch(error => console.error("Fehler:", error)); + .then(text => console.log("HTTP-Server says:", text)) + .catch(error => console.error("HTTP-Server - Error:", error)); } document.addEventListener("DOMContentLoaded", () => { diff --git a/frontend/index.html b/frontend/index.html index e3a618b..373974f 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -53,10 +53,11 @@
-

🧘 My I-Ging Horoscope

+

Do you want to know the future?

+

☝️ Look into the future with your personal I-Ging Horoscope! ☝️

Click on the Button to receive your personal Horoscope. 100% accuracy guaranteed!

- +
diff --git a/start.sh b/start.sh old mode 100644 new mode 100755