Sha256: a0ba8fff7ba61f650a783582c7d02ab5c36de914f9088cc1d6ec69ce6983c9c9

Contents?: true

Size: 556 Bytes

Versions: 1

Compression:

Stored size: 556 Bytes

Contents

require 'rack-proxy'

module HotReloadProxy
  class Proxy < Rack::Proxy
    WEBPACK_HOT_RELOAD_FILE_PATTERN = '.hot-update.'

    def initialize(app)
      @app = app
    end

    def call(env)
      # call super if we want to proxy
      (proxy?(env) && super) || @app.call(env)
    end

    def proxy?(env)
      Rack::Request.new(env).path.include?(WEBPACK_HOT_RELOAD_FILE_PATTERN)
    end

    def rewrite_env(env)
      port = HotReloadProxy.port
      host = HotReloadProxy.host
      env['HTTP_HOST'] = "#{host}:#{port}"
      env
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hot_reload_proxy-0.2.0 lib/hot_reload_proxy/proxy.rb