Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ForrestHub-app/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
return logging.getLogger(__name__)
13 changes: 13 additions & 0 deletions ForrestHub-app/assets/css/global_style.css
Original file line number Diff line number Diff line change
@@ -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;
Copy link

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded height calculation (256px + 30px border) creates a magic number that's tightly coupled to QR code dimensions. Consider using CSS calc() or making this more flexible to accommodate different QR code sizes.

Suggested change
border: 15px solid #ffffff !important;
--qrcode-size: 256px;
--qrcode-border: 15px;
.qrcode-wrapper {
display: inline-block;
background: #c2c2c2 !important;
padding: 0px;
height: calc(var(--qrcode-size) + 2 * var(--qrcode-border));
border: var(--qrcode-border) solid #ffffff !important;

Copilot uses AI. Check for mistakes.
border-radius: 10px;
}
.qrcode-wrapper canvas,
.qrcode-wrapper img {
display: block;
margin-top: -15px;
Copy link

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using negative margin to offset positioning is fragile and could break if the QR code dimensions change. Consider using flexbox or grid layout for more robust positioning.

Suggested change
margin-top: -15px;

Copilot uses AI. Check for mistakes.
}
16 changes: 12 additions & 4 deletions ForrestHub-app/assets/js/forrestHubLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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}`);
}

Expand Down
2 changes: 1 addition & 1 deletion ForrestHub-app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
USE_RELOADER = True
4 changes: 3 additions & 1 deletion ForrestHub-app/pages/admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ <h5 class="card-title"><i class="fa-solid fa-qrcode"></i> Připojení do hry</h5
</strong>
</p>
<p class="card-text"><small>Tuto adresu zadejte do prohlížeče na zařízení, které chcete připojit do hry.</small></p>
<div id="qrcode" class="mt-3"></div>
<div class="qrcode-wrapper">
<div id="qrcode" class="mt-3"></div>
</div>
<p><small>QR kód pro připojení do hry</small></p>
</div>
</div>
Expand Down
15 changes: 14 additions & 1 deletion ForrestHub-app/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@
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()


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,
)
Copy link

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forcing HTTPS scheme globally without checking if the application is actually running over HTTPS could cause issues in development or non-HTTPS environments. Consider making this conditional based on the actual deployment context.

Suggested change
)
# Preferuj https pro generované URL a zabezpeč cookies pouze pokud je povolen HTTPS
if getattr(config, "PREFERRED_URL_SCHEME", "http") == "https":
app.config.update(
PREFERRED_URL_SCHEME="https",
SESSION_COOKIE_SECURE=True,
REMEMBER_COOKIE_SECURE=True,
)
else:
app.config.update(
PREFERRED_URL_SCHEME="http",
SESSION_COOKIE_SECURE=False,
REMEMBER_COOKIE_SECURE=False,
)

Copilot uses AI. Check for mistakes.

socketio.run(
app,
host=host,
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion ForrestHub-app/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ <h5 class="modal-title" id="qrCodeModalLabel">QR Kód s aktuální adresou</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Zavřít"></button>
</div>
<div class="modal-body d-flex justify-content-center">
<div id="qrcode-page"></div>
<div class="qrcode-wrapper" style="padding-top: 15px;">
<div id="qrcode-page"></div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Zavřít</button>
Expand Down
Loading