SPA Handler¶
The AppHandler manages serving Single Page Applications in both development
and production modes.
Features¶
Development mode: Proxies requests to Vite dev server for HMR
Production mode: Serves built index.html with caching
CSRF token injection
Page data injection for Inertia.js
Async and sync initialization support
HTML transformation utilities
SPA mode handler public API.
This package provides the AppHandler for serving single-page applications with Vite asset integration.
- class litestar_vite.handler.AppHandler[source]¶
Bases:
objectHandler for serving SPA HTML in both dev and production modes.
- __init__(config: ViteConfig) None[source]¶
Initialize the SPA handler.
- Parameters:
config¶ – The Vite configuration.
- property is_initialized: bool¶
Whether the handler has been initialized.
- Returns:
True when initialized, otherwise False.
- async initialize_async(vite_url: str | None = None) None[source]¶
Initialize the handler asynchronously.
- Parameters:
vite_url¶ – Optional Vite server URL to use for proxying.
- initialize_sync(vite_url: str | None = None) None[source]¶
Initialize the handler synchronously.
- Parameters:
vite_url¶ – Optional Vite server URL to use for proxying.
- async get_html(request: Request[Any, Any, Any], *, page_data: dict[str, Any] | None = None) str[source]¶
Get the HTML for the SPA with optional transformations.
- get_html_sync(*, page_data: dict[str, Any] | None = None, csrf_token: str | None = None) str[source]¶
Get the HTML for the SPA synchronously.