diff --git a/README.md b/README.md index 6db6456..0e6ab14 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,6 @@ This app uses the I-Ching library app https://github.com/Velfi/i-ching.git. 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.--> -## First Start -The app can be deployed by running: - -```bash -$ kubectl apply -f deployment.yaml -``` This will start the deployment of the app in the pod, the service and an ingress for the HTTP frontend server and an ingress for the backend server. When a pod with the app is initally started, one email will be sent to the configured receiver. @@ -44,4 +38,33 @@ The Jest unit tests can be run with ```bash $ npm test ``` ---> \ No newline at end of file +--> + + +## Running the App + +### Locally +The app can be deployed locally by running: +The app can be deployed by running: +```bash +$ ./start-local.sh +``` +Der HTTP-Server can be access in a browser with the address http://localhost:8080/. + +### Locally with Docker +The app can be deployed by running: +```bash +$ docker run -e DEPLOY_MODE=docker -p 8080:8080 -p 8090:8090 --rm my-typescript-app +``` +Der HTTP-Server can be access in a browser with the address http://localhost:8080/. + +### In Kubernetes + +The app can be deployed by running: + +```bash +$ kubectl apply -f deployment.yaml +``` +Der HTTP-Server can be access in a browser with the address https://192-168-197-2.c-one-infra.de/iching/ + + \ No newline at end of file diff --git a/frontend/event.ts b/frontend/event.ts index 1735143..9b464a3 100644 --- a/frontend/event.ts +++ b/frontend/event.ts @@ -1,10 +1,11 @@ function handleClick(): void { console.log("Der Button wurde geklickt!"); - const deployMode = (window as { DEPLOY_MODE?: 'docker' | 'k8s' }).DEPLOY_MODE ?? 'k8s'; + //const deployMode = (window as { DEPLOY_MODE?: 'docker' | 'k8s' }).DEPLOY_MODE ?? 'k8s'; + const deployMode = (window as { DEPLOY_MODE?: 'docker' | 'k8s' | 'local' }).DEPLOY_MODE ?? 'k8s'; const endpoint = - deployMode === 'docker' + deployMode === 'docker' || deployMode === 'local' ? 'http://localhost:8090/iching/api/command' : '/iching/api/command'; diff --git a/package.json b/package.json index d28af51..4bfb90a 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,8 @@ "version": "1.0.0", "main": "broker.js", "scripts": { - "test": "jest --no-cache --force-exit" + "test": "jest --no-cache --force-exit", + "start:local": "tsc -p tsconfig.backend.json && tsc -p tsconfig.frontend.json && DEPLOY_MODE=local node dist/backend/server.js & npx http-server dist/frontend -p 8080 --cors --mime application/javascript=js" }, "keywords": [], "author": "", diff --git a/start-local.sh b/start-local.sh new file mode 100755 index 0000000..1b20eb7 --- /dev/null +++ b/start-local.sh @@ -0,0 +1,35 @@ + +# build +#npm install +#npx tsc -p tsconfig.backend.json +#npx tsc -p tsconfig.frontend.json + +#npm run start:local + +#!/bin/bash + +# Exit on error +set -e + +# 1. Install dependencies +npm install + +# 2. Compile backend and frontend +npx tsc -p tsconfig.backend.json +npx tsc -p tsconfig.frontend.json + +# 3. Ensure dist/frontend exists and copy index.html +mkdir -p dist/frontend +cp frontend/index.html dist/frontend/ + +# 4. Rename compiled frontend .js → .mjs +find dist/frontend -name "*.js" -exec bash -c 'mv "$0" "${0%.js}.mjs"' {} \; + +# 5. Inject deploy mode +echo "window.DEPLOY_MODE = 'local';" > dist/frontend/deploy.js + +# 6. Start backend +node dist/backend/server.js & + +# 7. Start frontend +npx http-server dist/frontend -p 8080 --cors --mime application/javascript=js