add http-server part 8.3 finish
All checks were successful
ci / build (push) Successful in 1m23s

This commit is contained in:
Christopher Hase 2025-04-14 11:24:56 +02:00
parent 9f82926037
commit ff7bf73e93
4 changed files with 20 additions and 45 deletions

View file

@ -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
<!--## Configuration
Properties of the app can be configured in the file config.json. It is possible to configure the mail host and port.
It is also possible to configure the intervall of days between the sending of horoscopes and the time of sending. The default is to send one email every seven days at 8 am.
It is also possible to configure the intervall of days between the sending of horoscopes and the time of sending. The default is to send one email every seven days at 8 am.-->
## 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).
<!--## Testing
The Jest unit tests can be run with
```bash
$ npm test
```
-->

View file

@ -18,8 +18,6 @@ interface Node {
//var config : Config;
//const nodemailer = require('nodemailer');
export function executeCommand(): void {
exec('iching divine', (error, stdout, stderr) => {

View file

@ -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();

View file

@ -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)); */