Skip to content

Commit fcada7c

Browse files
author
Juha Vuolle
committed
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: 156e5c8 Pick-to: 6.9 Fixes: QTBUG-134393 Change-Id: Iacfafe8a2fb2409169b09a17dbc9ffed0ad16fdf Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
1 parent 2a499eb commit fcada7c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

util/wasm/qtwasmserver/qtwasmserver.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from http import HTTPStatus
1616
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
1717
from subprocess import run
18+
from functools import partial
1819

1920
import brotli
2021
import netifaces as ni
@@ -155,7 +156,7 @@ def select_http_handler_class(compression_mode, address):
155156
return CompressionHttpRequesthandler
156157

157158

158-
# Serve cwd from http(s)://address:port, with certificates from certdir if set
159+
# Serve serve_path from http(s)://address:port, with certificates from certdir if set
159160
def serve_on_thread(
160161
address,
161162
port,
@@ -164,12 +165,13 @@ def serve_on_thread(
164165
cert_key_file,
165166
compression_mode,
166167
cross_origin_isolation,
168+
serve_path,
167169
):
168170
handler = select_http_handler_class(compression_mode, address)
169171
handler.cross_origin_isolation = cross_origin_isolation
170172

171173
try:
172-
httpd = ThreadingHTTPServer((address, port), handler)
174+
httpd = ThreadingHTTPServer((address, port), partial(handler, directory=serve_path))
173175
except Exception as e:
174176
print(f"\n### Error starting HTTP server: {e}\n")
175177
exit(1)
@@ -243,6 +245,10 @@ def main():
243245
serve_path = args.path
244246
cross_origin_isolation = args.cross_origin_isolation
245247

248+
if not os.path.isdir(serve_path):
249+
print(f"The provided path '{serve_path}' does not exist or is not a directory")
250+
exit(1)
251+
246252
compression_mode = CompressionMode.AUTO
247253
if args.compress_always:
248254
compression_mode = CompressionMode.ALWAYS
@@ -285,6 +291,7 @@ def main():
285291
cert_key_file,
286292
compression_mode,
287293
cross_origin_isolation,
294+
serve_path,
288295
)
289296

290297
if has_certificate:
@@ -298,6 +305,7 @@ def main():
298305
cert_key_file,
299306
compression_mode,
300307
cross_origin_isolation,
308+
serve_path,
301309
)
302310

303311

0 commit comments

Comments
 (0)