Skip to content

Commit c7941d5

Browse files
authored
examples : fix request path for local worker files (#2937)
This commit adds a fix to the server.py file to handle requests for web worker files when running the local python server to test the wasm examples. The motivation for this is that currently the server is serving files from the build-em/bin directory which is where the .worker.js files exist. But when examples access these resources they do so with the application context path, for example /whisper.wasm/libmain.worker.js but this will not be found as it currently works.
1 parent b82ac32 commit c7941d5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

examples/server.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,23 @@
1010
class CustomHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
1111
def __init__(self, *args, **kwargs):
1212
super().__init__(*args, directory=DIRECTORY, **kwargs)
13-
13+
14+
def do_GET(self):
15+
# If requesting a worker file from any subdirectory
16+
if '.worker.js' in self.path:
17+
worker_file = os.path.basename(self.path)
18+
worker_path = os.path.join(DIRECTORY, worker_file)
19+
20+
if os.path.exists(worker_path):
21+
self.path = '/' + worker_file
22+
23+
return super().do_GET()
24+
1425
def end_headers(self):
1526
# Add required headers for SharedArrayBuffer
1627
self.send_header("Cross-Origin-Opener-Policy", "same-origin")
1728
self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
29+
self.send_header("Access-Control-Allow-Origin", "*");
1830
super().end_headers()
1931

2032
PORT = 8000

0 commit comments

Comments
 (0)