2018-12-23 12:14:25 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
# This Rack middleware is intended to proxy the webpack assets directory to the
|
|
|
|
# webpack-dev-server. It is only intended for use in development.
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
# :nocov:
|
2017-08-17 22:00:37 +05:30
|
|
|
module Gitlab
|
2018-10-15 14:42:47 +05:30
|
|
|
module Webpack
|
|
|
|
class DevServerMiddleware < Rack::Proxy
|
2017-08-17 22:00:37 +05:30
|
|
|
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}")
|
2018-11-08 19:23:39 +05:30
|
|
|
if relative_url_root = Rails.application.config.relative_url_root
|
|
|
|
env['SCRIPT_NAME'] = ""
|
|
|
|
env['REQUEST_PATH'].sub!(/\A#{Regexp.escape(relative_url_root)}/, '')
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
super(env)
|
|
|
|
else
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
# :nocov:
|