From 5132d8824f83e35b00521d70510a11c9a62c9fc5 Mon Sep 17 00:00:00 2001 From: Felix Zumstein Date: Thu, 15 Aug 2024 14:16:58 +0200 Subject: [PATCH] respect XLWINGS_APP_PATH with socket.io service --- app/static/js/socketio-handlers.js | 7 ++++ docker-compose.yaml | 15 ++------ ...nginx-app-path.conf => nginx-apppath.conf} | 14 +++++--- tests/docker-compose.apppath.yaml | 36 +++++++++++++++++++ 4 files changed, 54 insertions(+), 18 deletions(-) rename nginx/{nginx-app-path.conf => nginx-apppath.conf} (76%) create mode 100644 tests/docker-compose.apppath.yaml diff --git a/app/static/js/socketio-handlers.js b/app/static/js/socketio-handlers.js index c83c1347..0f0ddcb3 100644 --- a/app/static/js/socketio-handlers.js +++ b/app/static/js/socketio-handlers.js @@ -1,6 +1,13 @@ +// XLWINGS_APP_PATH setting +const appPathElement = document.getElementById("app-path"); +const appPath = appPathElement ? JSON.parse(appPathElement.textContent) : null; + // Socket.io try { globalThis.socket = io({ + path: + (appPath && appPath.appPath !== "" ? `/${appPath.appPath}` : "") + + "/socket.io/", auth: async (callback) => { let token = await globalThis.getAuth(); callback({ diff --git a/docker-compose.yaml b/docker-compose.yaml index dcdac787..5ce6c542 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -8,7 +8,8 @@ services: command: > uvicorn app.main:main_app --host 0.0.0.0 --port 8000 - --ssl-keyfile /project/certs/localhost+2-key.pem --ssl-certfile /project/certs/localhost+2.pem + --ssl-keyfile /project/certs/localhost+2-key.pem + --ssl-certfile /project/certs/localhost+2.pem --reload --reload-dir /project/app ports: @@ -18,15 +19,3 @@ services: - ./certs:/project/certs env_file: - .env - - # nginx: - # # This requires the following settings: - # # XLWINGS_APP_PATH="/app" - # # XLWINGS_STATIC_URL_PATH="/app/static" - # # Note the port: https://127.0.0.1:8888/app/ - # image: nginx:latest - # ports: - # - "8888:443" - # volumes: - # - ./nginx/nginx-app-path.conf:/etc/nginx/conf.d/default.conf:ro - # - ./certs:/project/certs diff --git a/nginx/nginx-app-path.conf b/nginx/nginx-apppath.conf similarity index 76% rename from nginx/nginx-app-path.conf rename to nginx/nginx-apppath.conf index 236ce583..599a6cf4 100644 --- a/nginx/nginx-app-path.conf +++ b/nginx/nginx-apppath.conf @@ -1,4 +1,11 @@ +# ############################################### # This config mounts the app on /app instead of / +# +# This requires the following settings: +# +# XLWINGS_APP_PATH="/app" +# XLWINGS_STATIC_URL_PATH="/app/static" +# ############################################### server { listen 443 ssl; @@ -8,9 +15,6 @@ server { ssl_certificate_key /project/certs/localhost+2-key.pem; location /app { - # This requires the following settings: - # XLWINGS_APP_PATH="/app" - # XLWINGS_STATIC_URL_PATH="/app/static" proxy_pass https://app:8000; rewrite /app/(.*) /$1 break; @@ -20,8 +24,8 @@ server { proxy_set_header X-Forwarded-Proto $scheme; } - location /socket.io/ { - proxy_pass https://app:8000; + location /app/socket.io/ { + proxy_pass https://app:8000/socket.io/; proxy_http_version 1.1; proxy_buffering off; diff --git a/tests/docker-compose.apppath.yaml b/tests/docker-compose.apppath.yaml new file mode 100644 index 00000000..6744d405 --- /dev/null +++ b/tests/docker-compose.apppath.yaml @@ -0,0 +1,36 @@ +# ###################################### +# This requires the following settings: +# +# XLWINGS_APP_PATH="/app" +# XLWINGS_STATIC_URL_PATH="/app/static" +# ###################################### + +services: + nginx: + image: nginx:latest + ports: + - "8000:443" + volumes: + - ../nginx/nginx-apppath.conf:/etc/nginx/conf.d/default.conf:ro + - ../certs:/project/certs + + app: + build: + context: .. + target: dev + dockerfile: Dockerfile + command: > + uvicorn app.main:main_app + --host 0.0.0.0 --port 8000 + --ssl-keyfile /project/certs/localhost+2-key.pem + --ssl-certfile /project/certs/localhost+2.pem + --reload + --reload-dir /project/app + ports: + # Note port 8888 + - "8888:8000" + volumes: + - ../app:/project/app + - ../certs:/project/certs + env_file: + - ../.env