From ff7bf73e93addd4fb2b8fe75fe59b6707aad51bd Mon Sep 17 00:00:00 2001 From: Christopher Hase Date: Mon, 14 Apr 2025 11:24:56 +0200 Subject: [PATCH] add http-server part 8.3 finish --- README.md | 22 ++++++++++++++++++---- backend/broker.ts | 2 -- backend/server.ts | 24 +----------------------- frontend/event.ts | 17 +---------------- 4 files changed, 20 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 2599ac8..806f022 100644 --- a/README.md +++ b/README.md @@ -11,22 +11,36 @@ This app will send an I-Ching horoscope to the pre-configured mailhog instance i This app uses the I-Ching library app https://github.com/Velfi/i-ching.git. -## Configuration + ## First Start The app can be deployed by running: ```bash +$ kubectl apply -f ingress.yaml +$ kubectl apply -f service.yaml $ kubectl apply -f deployment.yaml ``` When a pod with the app is initally started, one email will be sent to the configured receiver. -## Testing +## Backend Server + +The backend server is running inside the pod on the address http://localhost:8090/command. If a POST is sent to this address, the server will run the main logic of this app: +An E-Mail with an I-Ching horoscope (provided by the library app) will be sent to the configured email address. + +The backend server can be tested from inside the pod by calling 'curl -X POST http://localhost:8090/command' from the console. + +## HTTP Server + +The frontend server is running inside the pod on the address http://localhost:8080/iching. It provides an HTML homepage with a button. Upon pressing the button, the backend server will be called (to send an E-Mail). + + \ No newline at end of file diff --git a/backend/broker.ts b/backend/broker.ts index ab96233..391235b 100644 --- a/backend/broker.ts +++ b/backend/broker.ts @@ -18,8 +18,6 @@ interface Node { //var config : Config; -//const nodemailer = require('nodemailer'); - export function executeCommand(): void { exec('iching divine', (error, stdout, stderr) => { diff --git a/backend/server.ts b/backend/server.ts index a5446b1..707fcd3 100644 --- a/backend/server.ts +++ b/backend/server.ts @@ -6,28 +6,6 @@ const app = express(); const port = 8090; app.use(cors()); -// CORS aktivieren und den Origin explizit setzen -/*app.use(cors({ - //origin: 'http://localhost:8080', // Erlaubt Anfragen vom Frontend (localhost:8080) - origin: 'http://127.0.0.1:8080', - //origin: 'https://192-168-197-2.c-one-infra.de', - methods: ['GET', 'POST', 'OPTIONS'], // Zulässige Methoden - allowedHeaders: ['Content-Type'], // Zulässige Header - credentials: true // Falls du Cookies oder Auth-Daten senden möchtest -})); - -// Füge dies hinzu, um die OPTIONS-Anfragen korrekt zu behandeln -app.options('/api/command', cors()); // für eine bestimmte Route - -// Verwende die Middleware, um POST-Body als JSON zu lesen -app.use(express.json()); - -app.use((req, res, next) => { - console.log('CORS headers set'); - next(); -});*/ - -//app.post('/api/command', (req, res) => { app.post('/command', (req, res) => { executeCommand(); @@ -36,4 +14,4 @@ app.post('/command', (req, res) => { app.listen(port, '0.0.0.0', () => { console.log(`Server läuft auf http://0.0.0.0:${port}`); -}); \ No newline at end of file +}); diff --git a/frontend/event.ts b/frontend/event.ts index e7f5fe5..321c88b 100644 --- a/frontend/event.ts +++ b/frontend/event.ts @@ -1,6 +1,6 @@ function handleClick(): void { console.log("Der Button wurde geklickt!"); - alert("Hallo von TypeScript!"); + //alert("Hallo von TypeScript!"); fetch("/iching/api/command", { method: "POST" }) .then(res => res.text()) @@ -12,18 +12,3 @@ document.addEventListener("DOMContentLoaded", () => { const button = document.getElementById("myButton"); button?.addEventListener("click", handleClick); }); - - - - //fetch("http://192-168-197-2.c-one-infra.de:8090/api/command", { method: "POST" }) - - //fetch("http://localhost:8090/api/command", { - //fetch("/api/command", { - - /*fetch("/api/command", { method: "POST" }) - .then(res => res.text()) - .then(text => console.log("Server sagt:", text));*/ - - /*fetch("https://192-168-197-2.c-one-infra.de/api/command", { method: "POST" }) - .then(res => res.text()) - .then(text => console.log("Server sagt:", text)); */ \ No newline at end of file