diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-25 21:47:58 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-09-25 21:48:16 -0300 |
| commit | 9c33714591a2147f7e5879e77212ca9886d0c967 (patch) | |
| tree | d250be9d9bc365d7894d49455c0f6376966b58be /tools | |
| download | sketchbook-9c33714591a2147f7e5879e77212ca9886d0c967.tar.gz sketchbook-9c33714591a2147f7e5879e77212ca9886d0c967.zip | |
Put the game first: lib/sketchbook, sketches/vecanim
The root is the game. The platform library moves to lib/sketchbook (with
serve_web.py, which serves any sketch's web build, as a tool of it), and
vecanim to sketches/vecanim, still its own package on the same library.
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/serve_web.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tools/serve_web.py b/tools/serve_web.py new file mode 100644 index 0000000..fd5b811 --- /dev/null +++ b/tools/serve_web.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +"""Serve only the built web directory on a LAN interface (no directory listing).""" +import argparse +from functools import partial +from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer +from pathlib import Path + +class Handler(SimpleHTTPRequestHandler): + extensions_map = {**SimpleHTTPRequestHandler.extensions_map, '.wasm': 'application/wasm'} + + def list_directory(self, path): + self.send_error(404) + return None + + def end_headers(self): + self.send_header('Cache-Control', 'no-cache') + super().end_headers() + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--root', type=Path, default=Path(__file__).resolve().parents[1] / 'zig-out/web') + parser.add_argument('--port', type=int, default=8042) + args = parser.parse_args() + root = args.root.resolve() + if not (root / 'sketch.wasm').is_file() or not (root / 'index.html').is_file(): + parser.error('Build first with zig build web; root must contain sketch.wasm and index.html') + server = ThreadingHTTPServer(('0.0.0.0', args.port), partial(Handler, directory=str(root))) + print(f'Serving {root} on 0.0.0.0:{args.port}', flush=True) + server.serve_forever() + +if __name__ == '__main__': + main() |
