danbev commited on
Commit
0d0eed6
·
unverified ·
1 Parent(s): aaf8a91

examples : fix request path for local worker files (#2937)

Browse files

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.

Files changed (1) hide show
  1. examples/server.py +13 -1
examples/server.py CHANGED
@@ -10,11 +10,23 @@ DIRECTORY = os.path.abspath(DIRECTORY)
10
  class CustomHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
11
  def __init__(self, *args, **kwargs):
12
  super().__init__(*args, directory=DIRECTORY, **kwargs)
13
-
 
 
 
 
 
 
 
 
 
 
 
14
  def end_headers(self):
15
  # Add required headers for SharedArrayBuffer
16
  self.send_header("Cross-Origin-Opener-Policy", "same-origin")
17
  self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
 
18
  super().end_headers()
19
 
20
  PORT = 8000
 
10
  class CustomHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
11
  def __init__(self, *args, **kwargs):
12
  super().__init__(*args, directory=DIRECTORY, **kwargs)
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
+
25
  def end_headers(self):
26
  # Add required headers for SharedArrayBuffer
27
  self.send_header("Cross-Origin-Opener-Policy", "same-origin")
28
  self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
29
+ self.send_header("Access-Control-Allow-Origin", "*");
30
  super().end_headers()
31
 
32
  PORT = 8000