Skip to content

Commit

Permalink
respect XLWINGS_APP_PATH with socket.io service
Browse files Browse the repository at this point in the history
  • Loading branch information
fzumstein committed Aug 15, 2024
1 parent 189541b commit 5132d88
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 18 deletions.
7 changes: 7 additions & 0 deletions app/static/js/socketio-handlers.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
15 changes: 2 additions & 13 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
14 changes: 9 additions & 5 deletions nginx/nginx-app-path.conf → nginx/nginx-apppath.conf
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down
36 changes: 36 additions & 0 deletions tests/docker-compose.apppath.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5132d88

Please sign in to comment.