diff --git a/ForrestHub-app/app/utils.py b/ForrestHub-app/app/utils.py index b3a3060..ef106d5 100644 --- a/ForrestHub-app/app/utils.py +++ b/ForrestHub-app/app/utils.py @@ -51,4 +51,4 @@ def setup_logging(root_dir: str, log_folder: str = "ForrestHubLogs"): console.setFormatter(formatter) logging.getLogger("").addHandler(console) - return logging.getLogger(__name__) \ No newline at end of file + return logging.getLogger(__name__) diff --git a/ForrestHub-app/assets/css/global_style.css b/ForrestHub-app/assets/css/global_style.css index e69de29..14bb23f 100644 --- a/ForrestHub-app/assets/css/global_style.css +++ b/ForrestHub-app/assets/css/global_style.css @@ -0,0 +1,13 @@ +.qrcode-wrapper { + display: inline-block; + background: #c2c2c2 !important; + padding: 0px; + height: 286px; /* 256px height + 15px border top + 15px border bottom */ + border: 15px solid #ffffff !important; + border-radius: 10px; +} +.qrcode-wrapper canvas, +.qrcode-wrapper img { + display: block; + margin-top: -15px; +} diff --git a/ForrestHub-app/assets/js/forrestHubLib.js b/ForrestHub-app/assets/js/forrestHubLib.js index 91726ce..ef2e1d4 100644 --- a/ForrestHub-app/assets/js/forrestHubLib.js +++ b/ForrestHub-app/assets/js/forrestHubLib.js @@ -13,7 +13,7 @@ class ForrestHubLib { * @param isGame {boolean} - zda se jedná o stránku hry * @param url {string} - URL serveru pro Socket.io (pokud není zadáno, použije se hostname + port) */ - constructor(isGame = true, url = "http://" + window.location.hostname + ":" + window.location.port) { + constructor(isGame = true, url) { if (ForrestHubLib.instance) { return ForrestHubLib.instance; } @@ -29,8 +29,12 @@ class ForrestHubLib { throw new Error('Socket.io není načteno.'); } - // Vytvoření socketu - this.socket = io.connect(url); + // Cesta pro Socket.IO (pokud je aplikace pod prefixem, např. /Udavač/, přidej ho) + const firstSeg = window.location.pathname.split('/')[1] || ''; + const socketPath = firstSeg ? `/socket.io/${encodeURIComponent(firstSeg)}` : '/socket.io'; + + // Vytvoření socketu bez pevného "http://", prohlížeč použije aktuální origin (vč. https) + this.socket = url ? io(url, { path: socketPath }) : io({ path: socketPath }); // Přidání základních event listenerů this.eventAddListener('connect', () => { @@ -215,7 +219,11 @@ class ForrestHubLib { socketSetServerUrl(url) { this.logDebug(`Měním serverové URL na: ${url}`); this.socketDisconnect(); - this.socket = io.connect(url); + + const firstSeg = window.location.pathname.split('/')[1] || ''; + const socketPath = firstSeg ? `/socket.io/${encodeURIComponent(firstSeg)}` : '/socket.io'; + + this.socket = url ? io(url, { path: socketPath }) : io({ path: socketPath }); this.logDebug(`Připojeno k novému serveru: ${url}`); } diff --git a/ForrestHub-app/config.py b/ForrestHub-app/config.py index 72dcee6..e07d2ea 100644 --- a/ForrestHub-app/config.py +++ b/ForrestHub-app/config.py @@ -52,4 +52,4 @@ class Config: # Disable debug and reloader when using frozen data with live data - production mode if not FROZEN: # DEBUG = False - USE_RELOADER = True \ No newline at end of file + USE_RELOADER = True diff --git a/ForrestHub-app/pages/admin/index.html b/ForrestHub-app/pages/admin/index.html index cc7440a..d21ce2a 100644 --- a/ForrestHub-app/pages/admin/index.html +++ b/ForrestHub-app/pages/admin/index.html @@ -22,7 +22,9 @@
Tuto adresu zadejte do prohlížeče na zařízení, které chcete připojit do hry.
- +QR kód pro připojení do hry
diff --git a/ForrestHub-app/run.py b/ForrestHub-app/run.py index fab192b..3b7ad59 100644 --- a/ForrestHub-app/run.py +++ b/ForrestHub-app/run.py @@ -6,7 +6,8 @@ from config import Config from pathlib import Path from app.utils import is_port_free, find_free_port, setup_logging - +from werkzeug.middleware.proxy_fix import ProxyFix +from app.utils import get_readable_ip logger = logging.getLogger(__name__) __version__ = (Path(__file__).parent / "VERSION").read_text().strip() @@ -14,6 +15,17 @@ def run_flask(config: object | str, host="0.0.0.0", port=4444): app = create_app(config) + + # Za reverzní proxy – respektuj X-Forwarded-* (host, proto, port, prefix) + app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_host=1, x_proto=1, x_port=1, x_prefix=1) + + # Preferuj https pro generované URL a zabezpeč cookies + app.config.update( + PREFERRED_URL_SCHEME="https", + SESSION_COOKIE_SECURE=True, + REMEMBER_COOKIE_SECURE=True, + ) + socketio.run( app, host=host, @@ -45,6 +57,7 @@ def main(port, host, host_qr, version): if host_qr: config.HOST_QR = host_qr + config.HOST_QR_READABLE = get_readable_ip(config.HOST, config.PORT, config.HOST_QR) if not is_port_free(config.HOST, config.PORT): new_port = find_free_port(config.HOST, 4444) diff --git a/ForrestHub-app/templates/header.html b/ForrestHub-app/templates/header.html index c02f38b..7e57106 100644 --- a/ForrestHub-app/templates/header.html +++ b/ForrestHub-app/templates/header.html @@ -33,7 +33,9 @@