Method: Froxy::Proxy#call

Defined in:
lib/froxy/proxy.rb

#call(env) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/froxy/proxy.rb', line 25

def call(env)
  req = Rack::Request.new(env)
  path_info = req.path_info

  if req.get? || req.head?
    # Let images through.
    return @file_server.call(env) if FALLTHRU_TYPES.match?(path_info)

    # Let JS sourcemaps through.
    return @build_file_server.call(env) if /\.js\.map$/i.match?(path_info)

    # Let esbuild handle JS and CSS.
    if /\.(js|jsx|css)$/i.match?(path_info)
      return unless (path = clean_path(path_info))
      return [404, {}, []] unless file_readable?(path)

      return @file_server.call(env) unless Rails.application.config.froxy.use_esbuild

      return benchmark logging_message(req) do
        build env, req, path
      end
    end
  end

  @app.call req.env
end