chessbaseLinux/apps/web/check/serve.py

38 lines
1.3 KiB
Python
Raw Normal View History

Web version, stage 1: the interface as a library over a platform layer; apps/web apps/desktop becomes a library (chesspenguin_app: the interface) and a thin binary; apps/web starts the same interface in a page's canvas (eframe's WebRunner). cfg(web) (build.rs) marks WebAssembly in a browser. The platform layer (apps/desktop/src/platform): the program's folders, files, background work, the files the user opens or saves, the clipboard and what the platform offers (CAPS). On a computer it is the system as before; in a browser the program's data lives in IndexedDB behind an in-memory file tree loaded before the start, the files the user opens are read into it for the session (only read), background jobs run on the page's thread after the frame, the clipboard is read through the browser's API, sounds play through audio elements, a game is saved as a download. What a browser does not have is not built for it: updates, the online games window and its probe, engine processes (analysis starts a Web Worker there; the review and preparation jobs, Rodent and the judge are native), blocking requests (engine, Maia and Rodent downloads report no download for the platform, translation reports that it makes no requests). The desktop program behaves as before; its build finds unused code (the web build compiles parts it never shows). apps/web: the entry point, the page /app/ (device check before anything large is loaded: phones and tablets get the page about the apps in the site's nine languages, keys app_* in website/site/i18n), build.sh (wasm-bindgen, profile web), a static server and headless Firefox checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 15:09:17 +03:00
"""The site's layout for the web version, locally: the built program at /app/ and the
site's static files at /static/ (screenshots of the device page). Only for checks:
the site itself serves /app/ when the web version is published (docs/dev/web.md).
python3 -I apps/web/check/serve.py <app-dir> <website-static-dir> [port]
"""
import functools
import http.server
import pathlib
import sys
APP, STATIC = pathlib.Path(sys.argv[1]).resolve(), pathlib.Path(sys.argv[2]).resolve()
PORT = int(sys.argv[3]) if len(sys.argv) > 3 else 18765
class Handler(http.server.SimpleHTTPRequestHandler):
extensions_map = {
**http.server.SimpleHTTPRequestHandler.extensions_map,
".wasm": "application/wasm",
".js": "text/javascript",
}
def translate_path(self, path):
path = path.split("?", 1)[0].split("#", 1)[0]
for prefix, base in (("/app/", APP), ("/static/", STATIC)):
if path.startswith(prefix):
target = (base / path[len(prefix):]).resolve()
if target == base or base in target.parents:
return str(target / "index.html" if target.is_dir() else target)
return str(APP / "__missing__")
def log_message(self, *args):
pass
http.server.ThreadingHTTPServer(("127.0.0.1", PORT), Handler).serve_forever()