class Rails::PWA::Interceptor

Attributes

app[R]
scripts[R]
server[R]

Public Class Methods

new(app, scripts:, root: false, **options) click to toggle source
# File lib/rails/pwa/interceptor.rb, line 6
def initialize(app, scripts:, root: false, **options)
  @app     = app
  @scripts = scripts.dup

  if root
    @server = ::Rack::File.new(root)
  else
    @server = app
  end
end

Public Instance Methods

call(env) click to toggle source
# File lib/rails/pwa/interceptor.rb, line 17
def call(env)
  if pack = scripts[env["PATH_INFO"]]
    respond_with_pack(env, pack)
  else
    app.call(env)
  end
end
respond_with_pack(env, pack) click to toggle source
# File lib/rails/pwa/interceptor.rb, line 25
def respond_with_pack(env, pack)
  path_info = env["PATH_INFO"]
  env["PATH_INFO"] = Webpacker.manifest.lookup!(pack)

  server.call(env)
ensure
  env["PATH_INFO"] = path_info
end