Class: ViteRuby::DevServerProxy

Inherits:
Rack::Proxy
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vite_ruby/dev_server_proxy.rb

Overview

Public: Allows to relay asset requests to the Vite development server.

Constant Summary collapse

HOST_WITH_PORT_REGEX =
%r{^(.+?)(:\d+)/}
VITE_DEPENDENCY_PREFIX =
"/@"

Instance Method Summary collapse

Constructor Details

#initialize(app = nil, options = {}) ⇒ DevServerProxy

Returns a new instance of DevServerProxy.



10
11
12
13
14
# File 'lib/vite_ruby/dev_server_proxy.rb', line 10

def initialize(app = nil, options = {})
  @vite_ruby = options.delete(:vite_ruby) || ViteRuby.instance
  options[:streaming] = false if config.mode == "test" && !options.key?(:streaming)
  super
end

Instance Method Details

#perform_request(env) ⇒ Object

Rack: Intercept asset requests and send them to the Vite server.



17
18
19
20
21
22
23
24
# File 'lib/vite_ruby/dev_server_proxy.rb', line 17

def perform_request(env)
  if vite_should_handle?(env) && dev_server_running?
    forward_to_vite_dev_server(env)
    super
  else
    @app.call(env)
  end
end