commit a7eba5dee10712e7fee0c2eb7e99d200967a99d2
parent 177cbcaf9ce8a68ac9a0c3722fd11547566eddeb
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date: Fri, 27 Sep 2024 20:38:55 +0200
feat: add ws proxy
Diffstat:
3 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/hcl/default/myheats-demo/myheats-demo.nomad b/hcl/default/myheats-demo/myheats-demo.nomad
@@ -25,10 +25,8 @@ job "myheats-demo" {
port "https" {
static = 44396
}
- port "http" {
- # VITE_API_PORT
- to = 8000
- }
+ port "api" {}
+ port "wss" {}
}
task "frontend" {
@@ -78,7 +76,7 @@ job "myheats-demo" {
config {
image = "127.0.0.1:5000/myheats-backend:latest"
force_pull = true
- ports = ["http"]
+ ports = ["api", "wss"]
volumes = [
# mount the templated config from the task directory to the container
"secrets/env:/app/.env.production",
diff --git a/hcl/default/myheats-demo/templates/env.local.tmpl b/hcl/default/myheats-demo/templates/env.local.tmpl
@@ -7,11 +7,13 @@ VITE_APP_DOC_TITLE='MyHeats Demo'
# Cookie TTL in seconds (session ttl in the admin/judges frontend), 60m
VITE_SESSION_TTL=259200 #27h
# Full URI to backend http API
-VITE_API_URI=http://{{ env "NOMAD_IP_http" }}
-# Full URI to backend websocket API
-VITE_API_WS=ws://{{ env "NOMAD_IP_http" }}
+VITE_API_URI=http://{{ env "NOMAD_IP_api" }}
# Backend API port
-VITE_API_PORT={{ env "NOMAD_PORT_http" }}
+VITE_API_PORT={{ env "NOMAD_PORT_api" }}
+# Full URI to backend websocket API
+VITE_WS_URI=wss://{{ env "NOMAD_ADDR_api" }}
+# Backend API websocket port
+VITE_WS_PORT={{ env "NOMAD_PORT_api" }}
# Locale for frontend date formatting
VITE_LOCALE=de-CH
diff --git a/hcl/default/myheats-demo/templates/nginx.conf.tmpl b/hcl/default/myheats-demo/templates/nginx.conf.tmpl
@@ -10,3 +10,23 @@ server {
try_files $uri /index.html;
}
}
+
+server {
+ listen {{ env "NOMAD_PORT_wss" }} ssl;
+
+ ssl_certificate /etc/letsencrypt/live/myheats-demo.p0c.ch/fullchain.pem;
+ ssl_certificate_key /etc/letsencrypt/live/myheats-demo.p0c.ch/privkey.pem;
+
+ location / {
+ proxy_pass http://{{ env "NOMAD_ADDR_api" }};
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+
+ # WebSocket support
+ proxy_http_version 1.1;
+ proxy_set_header Upgrade $http_upgrade;
+ proxy_set_header Connection "upgrade";
+ }
+}