Skip to content

fix: register gonertia middleware in router#53

Merged
felipekafuri merged 1 commit into
occult:mainfrom
MaracaipeDev:fix/register-gonertia-middleware
Feb 13, 2026
Merged

fix: register gonertia middleware in router#53
felipekafuri merged 1 commit into
occult:mainfrom
MaracaipeDev:fix/register-gonertia-middleware

Conversation

@MaracaipeDev

Copy link
Copy Markdown
Contributor

Summary

  • Register c.Inertia.Middleware in the Echo middleware chain via echo.WrapMiddleware(), placed right before middleware.InertiaProps()
  • This middleware is essential for the InertiaJS protocol but was missing from the router

What this middleware does

  1. Converts 302 → 303 for PUT/PATCH/DELETE — Without this, the browser follows the redirect keeping the original HTTP method (per the Fetch API spec), resulting in 404s
  2. Asset versioning — Forces a full page reload when frontend assets change, comparing X-Inertia-Version header
  3. Vary: X-Inertia header — Tells caches (CDN, proxy) that the response varies based on the X-Inertia header
  4. Empty response handling — Redirects the user back if an Inertia handler returns nothing

Why it wasn't caught earlier

Currently all delete routes use POST (e.g., profile.POST("/delete", ...)), so the 302→303 issue doesn't manifest. However, any future route using DELETE/PUT/PATCH with a redirect would break.

Test plan

  • go build -o /dev/null ./cmd/web — compiles without errors
  • make test — all tests passing

🤖 Generated with Claude Code

Add `echo.WrapMiddleware(c.Inertia.Middleware)` to the middleware chain
in the router. This middleware is essential for the InertiaJS protocol:

- Converts 302 redirects to 303 for PUT/PATCH/DELETE requests
- Handles asset versioning for frontend cache busting
- Sets the `Vary: X-Inertia` header
- Redirects back on empty Inertia responses

Without this, any future route using DELETE/PUT/PATCH with a redirect
would break because the browser follows the redirect keeping the
original HTTP method (per the Fetch API spec), resulting in 404s.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@felipekafuri felipekafuri merged commit 17ef64c into occult:main Feb 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants