"""Space entrypoint: physix.server.app:app + static UI mount. Adds two things on top of `physix.server.app:app`: 1. `GET /` and `GET /web` -> 302 to `/web/` (the OpenEnv app doesn't ship a root redirect, so the bare Space URL would otherwise 404). 2. `StaticFiles` mount at `/web/` for the built Vite SPA (Vite is built with `--base=/web/` so asset URLs already include the prefix). """ from __future__ import annotations from pathlib import Path from fastapi.responses import RedirectResponse from fastapi.staticfiles import StaticFiles from physix.server.app import app _STATIC_DIR = Path("/app/static") @app.get("/", include_in_schema=False) async def _root_redirect() -> RedirectResponse: return RedirectResponse(url="/web/") @app.get("/web", include_in_schema=False) async def _web_no_slash_redirect() -> RedirectResponse: return RedirectResponse(url="/web/") if _STATIC_DIR.is_dir(): # html=True makes StaticFiles serve index.html for directory hits and # fall back to it for unknown sub-paths so client-side routing works. app.mount( "/web", StaticFiles(directory=str(_STATIC_DIR), html=True), name="ui", )