This commit is contained in:
parent
9f82926037
commit
ff7bf73e93
4 changed files with 20 additions and 45 deletions
22
README.md
22
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.
|
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.
|
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
|
## First Start
|
||||||
The app can be deployed by running:
|
The app can be deployed by running:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
$ kubectl apply -f ingress.yaml
|
||||||
|
$ kubectl apply -f service.yaml
|
||||||
$ kubectl apply -f deployment.yaml
|
$ kubectl apply -f deployment.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
When a pod with the app is initally started, one email will be sent to the configured receiver.
|
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
|
The Jest unit tests can be run with
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm test
|
$ npm test
|
||||||
```
|
```
|
||||||
|
-->
|
|
@ -18,8 +18,6 @@ interface Node {
|
||||||
|
|
||||||
//var config : Config;
|
//var config : Config;
|
||||||
|
|
||||||
//const nodemailer = require('nodemailer');
|
|
||||||
|
|
||||||
export function executeCommand(): void {
|
export function executeCommand(): void {
|
||||||
|
|
||||||
exec('iching divine', (error, stdout, stderr) => {
|
exec('iching divine', (error, stdout, stderr) => {
|
||||||
|
|
|
@ -6,28 +6,6 @@ const app = express();
|
||||||
const port = 8090;
|
const port = 8090;
|
||||||
|
|
||||||
app.use(cors());
|
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) => {
|
app.post('/command', (req, res) => {
|
||||||
executeCommand();
|
executeCommand();
|
||||||
|
@ -36,4 +14,4 @@ app.post('/command', (req, res) => {
|
||||||
|
|
||||||
app.listen(port, '0.0.0.0', () => {
|
app.listen(port, '0.0.0.0', () => {
|
||||||
console.log(`Server läuft auf http://0.0.0.0:${port}`);
|
console.log(`Server läuft auf http://0.0.0.0:${port}`);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
function handleClick(): void {
|
function handleClick(): void {
|
||||||
console.log("Der Button wurde geklickt!");
|
console.log("Der Button wurde geklickt!");
|
||||||
alert("Hallo von TypeScript!");
|
//alert("Hallo von TypeScript!");
|
||||||
|
|
||||||
fetch("/iching/api/command", { method: "POST" })
|
fetch("/iching/api/command", { method: "POST" })
|
||||||
.then(res => res.text())
|
.then(res => res.text())
|
||||||
|
@ -12,18 +12,3 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||||
const button = document.getElementById("myButton");
|
const button = document.getElementById("myButton");
|
||||||
button?.addEventListener("click", handleClick);
|
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)); */
|
|
Loading…
Reference in a new issue