From 7ad9a2d391bbc22fae2f2cdbc3e49a85381a885c Mon Sep 17 00:00:00 2001 From: Juha Vuolle Date: Wed, 5 Mar 2025 09:02:20 +0200 Subject: [PATCH] qtwasmserver to serve assets from the provided path parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Fixes: QTBUG-134393 Change-Id: Iacfafe8a2fb2409169b09a17dbc9ffed0ad16fdf Reviewed-by: Morten Johan Sørvig (cherry picked from commit fcada7c5c395a7006ecef184c3ca43fff1023616) Reviewed-by: Qt Cherry-pick Bot --- util/wasm/qtwasmserver/qtwasmserver.py | 12 ++++++++++-- 1 file 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, )