Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/webpack/dev_server_middleware.rb')
-rw-r--r--lib/gitlab/webpack/dev_server_middleware.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/gitlab/webpack/dev_server_middleware.rb b/lib/gitlab/webpack/dev_server_middleware.rb
new file mode 100644
index 00000000000..b9a75eaac63
--- /dev/null
+++ b/lib/gitlab/webpack/dev_server_middleware.rb
@@ -0,0 +1,26 @@
+# 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: