From 1ddfc8c769ca094c6e0e4763076ec187f7a388ab Mon Sep 17 00:00:00 2001
From: Christopher Hase
Date: Tue, 15 Apr 2025 16:28:48 +0200
Subject: [PATCH 1/6] 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
From f5265a4e1d0b07bb52673475b9a23825eda566c6 Mon Sep 17 00:00:00 2001
From: Christopher Hase
Date: Wed, 16 Apr 2025 13:53:25 +0200
Subject: [PATCH 2/6] run in docker part 1.0
---
backend/broker.ts | 2 +-
deployment.yaml | 8 ++++++++
frontend/deploy.js | 1 +
frontend/event.ts | 11 ++++++++++-
frontend/index.html | 2 ++
start.sh | 10 ++++++++++
6 files changed, 32 insertions(+), 2 deletions(-)
create mode 100644 frontend/deploy.js
diff --git a/backend/broker.ts b/backend/broker.ts
index 5cbee8d..fc012a3 100644
--- a/backend/broker.ts
+++ b/backend/broker.ts
@@ -79,7 +79,7 @@ async function sendEmail(content: string) {
} catch (error) {
console.error("Error Sending E-Mail:", error + "\n\n");
- console.log("Failed to send horoscope: \n", content + "\n");
+ console.log("Failed to send this horoscope: \n", content + "\n");
}
}
diff --git a/deployment.yaml b/deployment.yaml
index e75a70c..6e77607 100644
--- a/deployment.yaml
+++ b/deployment.yaml
@@ -1,3 +1,11 @@
+#env:
+# - name: DEPLOY_MODE
+# value: "kubernetes"
+# - name: BACKEND_PORT
+# value: "8090"
+
+#---
+
# --- DEPLOYMENT --------------------------------------------
apiVersion: apps/v1
diff --git a/frontend/deploy.js b/frontend/deploy.js
new file mode 100644
index 0000000..12e8f02
--- /dev/null
+++ b/frontend/deploy.js
@@ -0,0 +1 @@
+window.DEPLOY_MODE = "k8s"
\ No newline at end of file
diff --git a/frontend/event.ts b/frontend/event.ts
index 3430561..1735143 100644
--- a/frontend/event.ts
+++ b/frontend/event.ts
@@ -1,7 +1,16 @@
function handleClick(): void {
console.log("Der Button wurde geklickt!");
- fetch("/iching/api/command", { method: "POST" })
+ const deployMode = (window as { DEPLOY_MODE?: 'docker' | 'k8s' }).DEPLOY_MODE ?? 'k8s';
+
+ const endpoint =
+ deployMode === 'docker'
+ ? 'http://localhost:8090/iching/api/command'
+ : '/iching/api/command';
+
+ console.log(`DEPLOY_MODE=${deployMode}, sende POST an: ${endpoint}`);
+
+ fetch(endpoint, { method: 'POST' })
.then(res => res.text())
.then(text => console.log("HTTP-Server says:", text))
.catch(error => console.error("HTTP-Server - Error:", error));
diff --git a/frontend/index.html b/frontend/index.html
index 373974f..9c6984a 100644
--- a/frontend/index.html
+++ b/frontend/index.html
@@ -60,6 +60,8 @@
+
+