debian-mirror-gitlab/lib/gitlab/webpack/dev_server_middleware.rb
2018-10-15 14:42:47 +05:30

26 lines
750 B
Ruby

# This Rack middleware is intended to proxy the webpack assets directory to the
# webpack-dev-server. It is only intended for use in development.
# :nocov:
module Gitlab
module Webpack
class DevServerMiddleware < Rack::Proxy
def initialize(app = nil, opts = {})
@proxy_host = opts.fetch(:proxy_host, 'localhost')
@proxy_port = opts.fetch(:proxy_port, 3808)
@proxy_path = opts[:proxy_path] if opts[:proxy_path]
super(app, backend: "http://#{@proxy_host}:#{@proxy_port}", **opts)
end
def perform_request(env)
if @proxy_path && env['PATH_INFO'].start_with?("/#{@proxy_path}")
super(env)
else
@app.call(env)
end
end
end
end
end
# :nocov: