Class: Webpacker::DevServerProxy

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

Instance Method Summary collapse

Instance Method Details

#perform_request(env) ⇒ Object


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

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

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

#rewrite_response(response) ⇒ Object


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

def rewrite_response(response)
  _status, headers, _body = response
  headers.delete "transfer-encoding"
  headers.delete "content-length" if Webpacker.dev_server.running? && Webpacker.dev_server.https?
  response
end