Documentation / @zerotal/inertia / InertiaMiddleware
Class: InertiaMiddleware
Defined in: inertia/src/middleware/InertiaMiddleware.ts:24
Must be registered as global middleware in Application.use() or in AppServiceProvider before other middleware.
Handles the Inertia protocol requirements:
-
303 redirect after POST/PUT/DELETE When a non-GET Inertia request results in a standard 302 redirect, Inertia requires a 303 to force the browser to GET the redirect target. Without this, browsers repeat the original POST method on the redirect.
-
Asset version mismatch (409 Conflict) If the client sends X-Inertia-Version that differs from the server's current asset version, respond with 409 and X-Inertia-Location header. This triggers a full page reload on the client to pick up new assets.
-
Always set Vary: X-Inertia on all responses Ensures browser cache treats HTML and JSON versions as distinct.
Extends
Constructors
Constructor
new InertiaMiddleware():
InertiaMiddleware
Defined in: core/src/middleware/BaseMiddleware.ts:36
Returns
InertiaMiddleware
Inherited from
Properties
options
protectedoptions:object={}
Defined in: inertia/src/middleware/InertiaMiddleware.ts:25
Subclasses must declare this with their default option values. TypeScript enforces this at compile time — forgetting it is a type error.
Overrides
Methods
with()
staticwith<T,Opts>(this,options): () =>InstanceType<T>
Defined in: core/src/middleware/BaseMiddleware.ts:48
Returns a zero-arg subclass with the given options deep-merged on top of the subclass defaults, usable directly in app.use([...]).
Type Parameters
T
T extends (...args) => BaseMiddleware<any>
Opts
Opts = T extends (...args) => BaseMiddleware<U> ? U : object
Parameters
this
T
options
Partial<Opts>
Returns
() => InstanceType<T>
Inherited from
afterResponse()?
optionalafterResponse(ctx):Promise<void>
Defined in: core/src/middleware/BaseMiddleware.ts:70
Parameters
ctx
Returns
Promise<void>
Inherited from
onError()?
optionalonError(ctx,error):Promise<void>
Defined in: core/src/middleware/BaseMiddleware.ts:71
Parameters
ctx
error
Error
Returns
Promise<void>
Inherited from
handle()
handle(
http,next):Promise<void|Response>
Defined in: inertia/src/middleware/InertiaMiddleware.ts:27
Parameters
http
next
Returns
Promise<void | Response>