Inertia Middleware¶
Middleware for handling Inertia.js protocol requirements.
The InertiaMiddleware automatically: - Detects Inertia requests via X-Inertia header - Manages version negotiation - Handles partial reloads - Processes deferred and merge props - Sets appropriate response headers
- litestar_vite.inertia.middleware.redirect_on_asset_version_mismatch(request: InertiaRequest[Any, Any, Any]) InertiaExternalRedirect | None[source]¶
Return redirect response when client and server asset versions differ.
- Returns:
An InertiaExternalRedirect when versions differ, otherwise None.
- class litestar_vite.inertia.middleware.InertiaMiddleware[source]¶
Bases:
AbstractMiddlewareMiddleware for handling Inertia.js protocol requirements.
This middleware: 1. Detects version mismatches between client and server assets 2. Returns 409 Conflict with X-Inertia-Location header when versions differ 3. Triggers client-side hard refresh to reload the updated assets
- __init__(app: ASGIApp) None[source]¶
Initialize the middleware.
- Parameters:
app¶ – The
nextASGI app to call.exclude¶ – A pattern or list of patterns to match against a request’s path. If a match is found, the middleware will be skipped.
exclude_opt_key¶ – An identifier that is set in the route handler
optkey which allows skipping the middleware.scopes¶ – ASGI scope types, should be a set including either or both ‘ScopeType.HTTP’ and ‘ScopeType.WEBSOCKET’.