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 Fixes: QTBUG-134393 Change-Id: Iacfafe8a2fb2409169b09a17dbc9ffed0ad16fdf Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> (cherry picked from commit fcada7c5c395a7006ecef184c3ca43fff1023616) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
aca60117ee
commit
7ad9a2d391
@ -15,6 +15,7 @@ from enum import Enum
|
|||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
|
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
|
||||||
from subprocess import run
|
from subprocess import run
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
import brotli
|
import brotli
|
||||||
import netifaces as ni
|
import netifaces as ni
|
||||||
@ -155,7 +156,7 @@ def select_http_handler_class(compression_mode, address):
|
|||||||
return CompressionHttpRequesthandler
|
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(
|
def serve_on_thread(
|
||||||
address,
|
address,
|
||||||
port,
|
port,
|
||||||
@ -164,12 +165,13 @@ def serve_on_thread(
|
|||||||
cert_key_file,
|
cert_key_file,
|
||||||
compression_mode,
|
compression_mode,
|
||||||
cross_origin_isolation,
|
cross_origin_isolation,
|
||||||
|
serve_path,
|
||||||
):
|
):
|
||||||
handler = select_http_handler_class(compression_mode, address)
|
handler = select_http_handler_class(compression_mode, address)
|
||||||
handler.cross_origin_isolation = cross_origin_isolation
|
handler.cross_origin_isolation = cross_origin_isolation
|
||||||
|
|
||||||
try:
|
try:
|
||||||
httpd = ThreadingHTTPServer((address, port), handler)
|
httpd = ThreadingHTTPServer((address, port), partial(handler, directory=serve_path))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"\n### Error starting HTTP server: {e}\n")
|
print(f"\n### Error starting HTTP server: {e}\n")
|
||||||
exit(1)
|
exit(1)
|
||||||
@ -243,6 +245,10 @@ def main():
|
|||||||
serve_path = args.path
|
serve_path = args.path
|
||||||
cross_origin_isolation = args.cross_origin_isolation
|
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
|
compression_mode = CompressionMode.AUTO
|
||||||
if args.compress_always:
|
if args.compress_always:
|
||||||
compression_mode = CompressionMode.ALWAYS
|
compression_mode = CompressionMode.ALWAYS
|
||||||
@ -285,6 +291,7 @@ def main():
|
|||||||
cert_key_file,
|
cert_key_file,
|
||||||
compression_mode,
|
compression_mode,
|
||||||
cross_origin_isolation,
|
cross_origin_isolation,
|
||||||
|
serve_path,
|
||||||
)
|
)
|
||||||
|
|
||||||
if has_certificate:
|
if has_certificate:
|
||||||
@ -298,6 +305,7 @@ def main():
|
|||||||
cert_key_file,
|
cert_key_file,
|
||||||
compression_mode,
|
compression_mode,
|
||||||
cross_origin_isolation,
|
cross_origin_isolation,
|
||||||
|
serve_path,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user