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