Class: Webpacker::DevServerProxy

Inherits:
Rack::Proxy
  • Object
show all
Defined in:
lib/webpacker/dev_server_proxy.rb

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of DevServerProxy.



6
7
8
9
10
# File 'lib/webpacker/dev_server_proxy.rb', line 6

def initialize(app = nil, opts = {})
  @webpacker = opts.delete(:webpacker) || Webpacker.instance
  opts[:streaming] = false if Jets.env.test? && !opts.key?(:streaming)
  super
end

Instance Method Details

#perform_request(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/webpacker/dev_server_proxy.rb', line 12

def perform_request(env)
  if env["PATH_INFO"].start_with?("/#{public_output_uri_path}") && dev_server.running?
    env["HTTP_HOST"] = env["HTTP_X_FORWARDED_HOST"] = dev_server.host
    env["HTTP_X_FORWARDED_SERVER"] = dev_server.host_with_port
    env["HTTP_PORT"] = env["HTTP_X_FORWARDED_PORT"] = dev_server.port.to_s
    env["HTTP_X_FORWARDED_PROTO"] = env["HTTP_X_FORWARDED_SCHEME"] = dev_server.protocol
    unless dev_server.https?
      env["HTTPS"] = env["HTTP_X_FORWARDED_SSL"] = "off"
    end
    env["SCRIPT_NAME"] = ""

    super(env)
  else
    @app.call(env)
  end
end