summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuha Vuolle <[email protected]>2025-03-05 09:02:20 +0200
committerJuha Vuolle <[email protected]>2025-03-07 13:02:47 +0200
commitfcada7c5c395a7006ecef184c3ca43fff1023616 (patch)
treec01838f3017d9e2c353ac6655e7d55673169d22d
parent2a499eb8d7f593ae66a54d34fef05d713d5aea7b (diff)
qtwasmserver to serve assets from the provided path parameter
qtwasmserver accepts a positional path argument which tells where to serve the assets from. The argument wasn't actually used, and this resulted in always using the cwd. In addition add a check for the path directory existence. Otherwise this becomes only visible as a 404 Not Found error. Amends: 156e5c8b690d01ad3043d2163168c4ea3608a046 Pick-to: 6.9 Fixes: QTBUG-134393 Change-Id: Iacfafe8a2fb2409169b09a17dbc9ffed0ad16fdf Reviewed-by: Morten Johan Sørvig <[email protected]>
-rwxr-xr-xutil/wasm/qtwasmserver/qtwasmserver.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/util/wasm/qtwasmserver/qtwasmserver.py b/util/wasm/qtwasmserver/qtwasmserver.py
index ddc95de13d1..208717a0bad 100755
--- a/util/wasm/qtwasmserver/qtwasmserver.py
+++ b/util/wasm/qtwasmserver/qtwasmserver.py
@@ -15,6 +15,7 @@ from enum import Enum
from http import HTTPStatus
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
from subprocess import run
+from functools import partial
import brotli
import netifaces as ni
@@ -155,7 +156,7 @@ def select_http_handler_class(compression_mode, address):
return CompressionHttpRequesthandler
-# Serve cwd from http(s)://address:port, with certificates from certdir if set
+# Serve serve_path from http(s)://address:port, with certificates from certdir if set
def serve_on_thread(
address,
port,
@@ -164,12 +165,13 @@ def serve_on_thread(
cert_key_file,
compression_mode,
cross_origin_isolation,
+ serve_path,
):
handler = select_http_handler_class(compression_mode, address)
handler.cross_origin_isolation = cross_origin_isolation
try:
- httpd = ThreadingHTTPServer((address, port), handler)
+ httpd = ThreadingHTTPServer((address, port), partial(handler, directory=serve_path))
except Exception as e:
print(f"\n### Error starting HTTP server: {e}\n")
exit(1)
@@ -243,6 +245,10 @@ def main():
serve_path = args.path
cross_origin_isolation = args.cross_origin_isolation
+ if not os.path.isdir(serve_path):
+ print(f"The provided path '{serve_path}' does not exist or is not a directory")
+ exit(1)
+
compression_mode = CompressionMode.AUTO
if args.compress_always:
compression_mode = CompressionMode.ALWAYS
@@ -285,6 +291,7 @@ def main():
cert_key_file,
compression_mode,
cross_origin_isolation,
+ serve_path,
)
if has_certificate:
@@ -298,6 +305,7 @@ def main():
cert_key_file,
compression_mode,
cross_origin_isolation,
+ serve_path,
)