justapi — /docs

Serve a Frontend

Mount a static directory as an SPA:

from justapi import JustAPIApp

app = JustAPIApp()

@app.frontend("/", directory="dist")
def serve_frontend():
    pass

This serves dist/ at / and handles client-side routing (any path not matching an API route returns index.html).

With API Routes

app = JustAPIApp()

@app.get("/api/hello")
def hello():
    return {"message": "Hello from API"}

# Must come AFTER API routes
@app.frontend("/", directory="dist")
def serve_frontend():
    pass

:::note Place frontend() after all API routes so API paths take priority. :::

Parameters

Parameter Type Default Description
path str Mount path
directory str Static file directory
html str None Custom index HTML (overrides file)
check_dir bool True Raise error if directory doesn't exist

Custom HTML

@app.frontend("/", html="<h1>My App</h1>")
def serve():
    pass

See Also

JustAPI v2.0.9 — Open Source MIT License · Built with WebTUI · GitHub

NORMAL master justapi/docs
utf-8 Top 1:1