From 4b4f35b5466d5f12fa1527e2c4cee99122c0e507 Mon Sep 17 00:00:00 2001 From: Christopher Hase Date: Fri, 4 Apr 2025 11:48:30 +0200 Subject: [PATCH] add http-server --- Dockerfile | 18 +++++++-- broker.test.ts => iching/broker.test.ts | 0 broker.ts => iching/broker.ts | 49 +------------------------ config.json => iching/config.json | 2 - iching/event.ts | 13 +++++++ iching/index.html | 13 +++++++ 6 files changed, 41 insertions(+), 54 deletions(-) rename broker.test.ts => iching/broker.test.ts (100%) rename broker.ts => iching/broker.ts (77%) rename config.json => iching/config.json (71%) create mode 100644 iching/event.ts create mode 100644 iching/index.html diff --git a/Dockerfile b/Dockerfile index 9449b94..85298db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,13 @@ COPY . . #RUN npm install RUN npm install -g npm@11.2.0 -RUN npx tsc # TypeScript Code kompilieren +RUN npx tsc + + +### NEW ### +RUN npm install -g http-server +RUN npx tsc iching/event.ts + # 2. Rust build-Stage FROM forgejo.edf-bootstrap.cx.fg1.ffm.osc.live/devfw-cicd/rust:1.74.0 AS rust-build @@ -24,7 +30,11 @@ COPY --from=build /app . COPY --from=rust-build /usr/local/cargo/bin/iching /usr/local/bin/iching # 5. Run app -CMD ["npx", "ts-node", "broker.ts"] +#CMD ["npx", "ts-node", "broker.ts"] -#run indefinitely to avoid CrashLoopBackOff -#CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" +### NEW ### +#RUN npx ts-node event.ts + + +#CMD ["http-server", "."] +CMD ["npx", "http-server", "-p", "1234"] diff --git a/broker.test.ts b/iching/broker.test.ts similarity index 100% rename from broker.test.ts rename to iching/broker.test.ts diff --git a/broker.ts b/iching/broker.ts similarity index 77% rename from broker.ts rename to iching/broker.ts index 30c65ec..07940d1 100644 --- a/broker.ts +++ b/iching/broker.ts @@ -3,8 +3,6 @@ import * as fs from 'fs'; // Config for scheduling the next time the main process (sending of horoscope) is run interface Config { - daysInterval: number; - timeOfDay: string; emailReceiver: string; mailHost: string; mailPort: number; @@ -21,7 +19,7 @@ var config : Config; const nodemailer = require('nodemailer'); -function executeCommand(): void { +export function executeCommand(): void { exec('iching divine', (error, stdout, stderr) => { @@ -44,13 +42,6 @@ function executeCommand(): void { console.log(`Send E-Mail`); sendEmail(stdout); - - // Calculate next execution time - const nextRunDate = calculateNextRunDate(config.daysInterval, config.timeOfDay); - console.log(`Next execution: ${nextRunDate}`); - - // Start Scheduling - scheduleNextRun(nextRunDate); }); } @@ -91,44 +82,6 @@ async function sendEmail(content: string) { } } -//Calculate the time for the next execution of the main process, depending on configuration. -//Returns the time of the next process loop. -function calculateNextRunDate(daysInterval: number, timeOfDay: string): Date { - const currentDate = new Date(); - - // Splitte die Uhrzeit in Stunden und Minuten - const [hours, minutes] = timeOfDay.split(':').map(Number); - - // Berechne das Datum für die nächste Ausführung - currentDate.setHours(hours, minutes, 0, 0); // Setze die Uhrzeit auf Y (z.B. 14:30) - - // Wenn die Uhrzeit bereits vorbei ist, verschiebe das Datum auf den nächsten Tag - if (currentDate < new Date()) { - currentDate.setDate(currentDate.getDate() + 1); // Setze auf den nächsten Tag - } - - // Berechne das Datum für den nächsten Ausführungszeitpunkt unter Berücksichtigung von X Tagen - currentDate.setDate(currentDate.getDate() + daysInterval); - - return currentDate; -} - -//Schedule the next process loop. -function scheduleNextRun(nextRunDate: Date) { - const now = new Date(); - const timeUntilNextRun = nextRunDate.getTime() - now.getTime(); - - if (timeUntilNextRun > 0) { - setTimeout(() => { - console.log('Next iteration of Process was scheduled!'); - - //run the main process - executeCommand(); - - }, timeUntilNextRun); - } -} - // Generate 1) Parse Tree and 2) HTML export function html(inputText: string): string { const parseTree = parse(inputText); diff --git a/config.json b/iching/config.json similarity index 71% rename from config.json rename to iching/config.json index 92bec07..121311d 100644 --- a/config.json +++ b/iching/config.json @@ -1,6 +1,4 @@ { - "daysInterval": 7, - "timeOfDay": "8:00", "emailReceiver": "test@mailhog.local", "mailHost": "mailhog.mailhog.svc.cluster.local", "mailPort": 1025 diff --git a/iching/event.ts b/iching/event.ts new file mode 100644 index 0000000..9d66fad --- /dev/null +++ b/iching/event.ts @@ -0,0 +1,13 @@ +import { executeCommand } from './broker'; + +function handleClick(): void { + console.log("Der Button wurde geklickt!"); + alert("Hallo von TypeScript!"); + + executeCommand(); +} + +document.addEventListener("DOMContentLoaded", () => { + const button = document.getElementById("myButton"); + button?.addEventListener("click", handleClick); +}); \ No newline at end of file diff --git a/iching/index.html b/iching/index.html new file mode 100644 index 0000000..1b3bffa --- /dev/null +++ b/iching/index.html @@ -0,0 +1,13 @@ + + + + + Button mit TypeScript + + +

Mein Button

+ + + + + \ No newline at end of file