Class: Froxy::Proxy
- Inherits:
-
Object
- Object
- Froxy::Proxy
- Defined in:
- lib/froxy/proxy.rb
Constant Summary collapse
- BUILD_PATH =
'public/froxy/build'- CLI =
File.('../../bin/froxy', __dir__)
- IMAGE_TYPES =
/\.(png|gif|jpeg|jpg|svg|ico|webp|avif)$/i.freeze
- FILE_EXT_MAP =
{ '.jsx' => '.js' }.freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Proxy
constructor
A new instance of Proxy.
Constructor Details
#initialize(app) ⇒ Proxy
16 17 18 19 20 |
# File 'lib/froxy/proxy.rb', line 16 def initialize(app) @app = app @file_server = Rack::Files.new(Rails.root) @build_file_server = Rack::Files.new(Rails.root.join(BUILD_PATH)) end |
Instance Method Details
#call(env) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/froxy/proxy.rb', line 22 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 IMAGE_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 build env, req, path end end @app.call req.env end |