2017-02-01 14:05:33 -05:00
|
|
|
# This Rack middleware is intended to proxy the webpack assets directory to the
|
|
|
|
# webpack-dev-server. It is only intended for use in development.
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Middleware
|
|
|
|
class WebpackProxy < 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]
|
2017-02-27 01:32:50 -05:00
|
|
|
|
2017-02-27 13:20:00 -05:00
|
|
|
super(app, backend: "http://#{@proxy_host}:#{@proxy_port}", **opts)
|
2017-02-01 14:05:33 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def perform_request(env)
|
2017-02-27 01:32:50 -05:00
|
|
|
if @proxy_path && env['PATH_INFO'].start_with?("/#{@proxy_path}")
|
|
|
|
super(env)
|
|
|
|
else
|
|
|
|
@app.call(env)
|
2017-02-01 14:05:33 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|