Class: InertiaHanami::Middleware::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/inertia_hanami/middleware/version.rb

Overview

Plain Rack middleware implementing the Inertia protocol's asset versioning handshake: on a GET Inertia request whose X-Inertia-Version header doesn't match the server's configured version, respond with a 409 + X-Inertia-Location (empty body) instead of calling downstream, so the client performs a full browser visit and picks up new assets.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Version

Returns a new instance of Version.



13
14
15
# File 'lib/inertia_hanami/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
# File 'lib/inertia_hanami/middleware/version.rb', line 17

def call(env)
  request_context = RequestContext.new(env)

  if stale?(env, request_context)
    request = Rack::Request.new(env)
    return [409, { "X-Inertia-Location" => request.url }, [""]]
  end

  @app.call(env)
end