Class: Inertia::Middleware::Version
- Inherits:
-
Object
- Object
- Inertia::Middleware::Version
- Defined in:
- lib/inertia/middleware/version.rb
Overview
Rack middleware that enforces Inertia asset version consistency.
For GET requests carrying X-Inertia-Version, compares the client version
with Frontend.version. A mismatch returns 409 with X-Inertia-Location,
prompting the client to reload the current URL with the latest assets.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Version
constructor
A new instance of Version.
Constructor Details
#initialize(app) ⇒ Version
Returns a new instance of Version.
13 14 15 |
# File 'lib/inertia/middleware/version.rb', line 13 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/inertia/middleware/version.rb', line 17 def call(env) return @app.call(env) unless env["REQUEST_METHOD"] == "GET" client_version = env["HTTP_X_INERTIA_VERSION"] if client_version.nil? || client_version == server_version @app.call(env) else [409, { "x-inertia-location" => Rack::Request.new(env).url }, []] end end |