Sha256: 6e89d6dfcfb5bde786e032dd156094f06f7269fe9dde632aad71fa46115d92f2

Contents?: true

Size: 1.04 KB

Versions: 54

Compression:

Stored size: 1.04 KB

Contents

require "rack/proxy"

class Webpacker::DevServerProxy < Rack::Proxy
  delegate :config, :dev_server, to: :@webpacker

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

  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

  private
    def public_output_uri_path
      config.public_output_path.relative_path_from(config.public_path).to_s + "/"
    end
end

Version data entries

54 entries across 54 versions & 3 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/webpacker-5.4.4/lib/webpacker/dev_server_proxy.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/webpacker-5.4.4/lib/webpacker/dev_server_proxy.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/webpacker-5.4.4/lib/webpacker/dev_server_proxy.rb
shakapacker-6.6.0 lib/webpacker/dev_server_proxy.rb
shakapacker-6.5.6 lib/webpacker/dev_server_proxy.rb
webpacker-5.4.4 lib/webpacker/dev_server_proxy.rb
shakapacker-6.5.5 lib/webpacker/dev_server_proxy.rb
shakapacker-6.5.4 lib/webpacker/dev_server_proxy.rb
shakapacker-6.5.3 lib/webpacker/dev_server_proxy.rb
shakapacker-6.5.2 lib/webpacker/dev_server_proxy.rb
shakapacker-6.5.1 lib/webpacker/dev_server_proxy.rb
shakapacker-6.5.0 lib/webpacker/dev_server_proxy.rb
shakapacker-6.4.1 lib/webpacker/dev_server_proxy.rb
shakapacker-6.4.0 lib/webpacker/dev_server_proxy.rb
shakapacker-6.3.0 lib/webpacker/dev_server_proxy.rb
shakapacker-6.3.0.pre.rc.1 lib/webpacker/dev_server_proxy.rb
shakapacker-6.2.1 lib/webpacker/dev_server_proxy.rb
shakapacker-6.2.0 lib/webpacker/dev_server_proxy.rb
shakapacker-6.1.1 lib/webpacker/dev_server_proxy.rb
shakapacker-6.1.0 lib/webpacker/dev_server_proxy.rb