swadhinbiswas πŸš€ release: 2.0.8 β€” write-path fix (ADR-080), fork-safe GIL pool (ADR-081), HTTP/3 (ADR-082), Security DI fix, docs honesty pass Β· 8/6/2026
731fffe
62 lines Β· 1.6 KB
Raw Download

title: Static Files
description: Serve static files (HTML, CSS, JS, images) from a JustAPI application.
keywords: [JustAPI, static files, assets, mount, CSS, JavaScript]

Basic Static Files

Serve files from a directory at a path prefix:

from justapi import JustAPIApp

app = JustAPIApp()

app.frontend("/static", "static")

This serves files from the static/ directory at /static/. For example, static/style.css is accessible at /static/style.css.

Custom Mount Point

# Serve at /assets/*
app.frontend("/assets", "public/assets")

Multiple Static Directories

app.frontend("/css", "static/css")
app.frontend("/js", "static/js")
app.frontend("/images", "static/images")

Mounting an APIRouter as a Sub-application

JustAPI supports mounting an APIRouter at a path prefix:

from justapi import APIRouter, JustAPIApp

app = JustAPIApp()

# Serve a static SPA with index.html fallback for client-side routing
app.frontend("/", "public", html=True)

# Mount a router as a sub-application
router = APIRouter(prefix="/api/v2")
app.mount("/api/v2", router, name="v2")

JustAPI does not mount third-party ASGI/Starlette applications β€” the runtime
is a native Rust pipeline. Use APIRouter for sub-app structure, or place
JustAPI behind a path-routing reverse proxy to co-host legacy apps.

See Also