Skip to content

shared

asset_url

Python
asset_url(name: str) -> str

The URL a template loads a built frontend file from: /mojo-static/dist/<name>, or the TypeScript or CSS source Vite serves for it when MOJO_DOJO_DEV is set. name is a key of ts/entries.json, the list vite.config.ts builds from too, so an unknown name raises KeyError in dev.

Source code in src/mujoco_mojo/utils/layers/dojo/shared.py
Python
def asset_url(name: str) -> str:
    """The URL a template loads a built frontend file from: `/mojo-static/dist/<name>`, or the TypeScript or CSS source Vite serves for it when `MOJO_DOJO_DEV` is set. `name` is a key of `ts/entries.json`, the list `vite.config.ts` builds from too, so an unknown name raises `KeyError` in dev."""
    if not VITE_DEV:
        return f"/mojo-static/dist/{name}"
    entries: dict[str, str] = json.loads((TS_DIR / "entries.json").read_text())
    return f"/{entries[name]}"

is_localhost

Python
is_localhost(request: Request) -> bool

Whether the request's direct TCP peer is the loopback interface, regardless of which interface the server itself is bound to. Shared by every router that gates a write behind "only from the machine running Dojo" (settings, and the What's Changed toggle).

Source code in src/mujoco_mojo/utils/layers/dojo/shared.py
Python
def is_localhost(request: Request) -> bool:
    """Whether the request's direct TCP peer is the loopback interface, regardless of which interface the server itself is bound to. Shared by every router that gates a write behind "only from the machine running Dojo" (settings, and the What's Changed toggle)."""
    host = request.client.host if request.client else None
    if host is None:
        return False
    try:
        return ipaddress.ip_address(host).is_loopback
    except ValueError:
        return False