Skip to main content
zerotal

Documentation


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:

  1. 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.

  2. 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.

  3. 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

BaseMiddleware.constructor

Properties

options

protected options: 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

BaseMiddleware.options

Methods

with()

static with<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

BaseMiddleware.with


afterResponse()?

optional afterResponse(ctx): Promise<void>

Defined in: core/src/middleware/BaseMiddleware.ts:70

Parameters

ctx

HttpContext

Returns

Promise<void>

Inherited from

BaseMiddleware.afterResponse


onError()?

optional onError(ctx, error): Promise<void>

Defined in: core/src/middleware/BaseMiddleware.ts:71

Parameters

ctx

HttpContext

error

Error

Returns

Promise<void>

Inherited from

BaseMiddleware.onError


handle()

handle(http, next): Promise<void | Response>

Defined in: inertia/src/middleware/InertiaMiddleware.ts:27

Parameters

http

HttpContext

next

NextFn

Returns

Promise<void | Response>

Overrides

BaseMiddleware.handle