Permalink
Browse files

Support for adding reverse proxy friendly url prefixes

Summary
-
In order for resque-web to be put behind a reverse-proxy path
that is not root, resque-web must serve templates with asset and
url links with the reverse proxy url prefix.

The url prefix can be added using '-a' option. e.g:
./resque-web -F -L -s thin -p 5678 -e development -a '/proxy_sites/resque'

Tests Ran:
-
Existing tests with additional url_prefix use case
  • Loading branch information...
1 parent b06ab91 commit bf34140f08970f6062ae842a651ee03039da0217 @jpang-h4 jpang-h4 committed Jan 9, 2016
Showing with 34 additions and 4 deletions.
  1. +4 −0 bin/resque-web
  2. +20 −4 lib/resque/server.rb
  3. +10 −0 test/resque-web_test.rb
View
@@ -24,4 +24,8 @@ Vegas::Runner.new(Resque::Server, 'resque-web', {
runner.logger.info "Using Redis connection '#{redis_conf}'"
Resque.redis = redis_conf
}
+ opts.on('-a url-prefix', "--append url-prefix", "set reverse_proxy friendly prefix to links") {|url_prefix|
+ runner.logger.info "Using URL Prefix '#{url_prefix}'"
+ Resque::Server.url_prefix = url_prefix
+ }
end
View
@@ -38,10 +38,14 @@ def current_page
end
def url_path(*path_parts)
- [ path_prefix, path_parts ].join("/").squeeze('/')
+ [ url_prefix, path_prefix, path_parts ].join("/").squeeze('/')
end
alias_method :u, :url_path
+ def redirect_url_path(*path_parts)
+ [ path_prefix, path_parts ].join("/").squeeze('/')
+ end
+
def path_prefix
request.env['SCRIPT_NAME']
end
@@ -60,6 +64,10 @@ def tabs
Resque::Server.tabs
end
+ def url_prefix
+ Resque::Server.url_prefix
+ end
+
def redis_get_size(key)
case Resque.redis.type(key)
when 'none'
@@ -150,7 +158,7 @@ def show_for_polling(page)
# to make things easier on ourselves
get "/?" do
- redirect url_path(:overview)
+ redirect redirect_url_path(:overview)
end
%w( overview workers ).each do |page|
@@ -213,7 +221,7 @@ def show_for_polling(page)
post "/failed/:queue/requeue/all" do
Resque::Failure.requeue_queue Resque::Failure.job_queue_name(params[:queue])
- redirect url_path("/failed/#{params[:queue]}")
+ redirect redirect_url_path("/failed/#{params[:queue]}")
end
get "/failed/requeue/:index/?" do
@@ -231,7 +239,7 @@ def show_for_polling(page)
end
get "/stats/?" do
- redirect url_path("/stats/resque")
+ redirect redirect_url_path("/stats/resque")
end
get "/stats/:id/?" do
@@ -267,5 +275,13 @@ def resque
def self.tabs
@tabs ||= ["Overview", "Working", "Failed", "Queues", "Workers", "Stats"]
end
+
+ def self.url_prefix=(url_prefix)
+ @url_prefix = url_prefix
+ end
+
+ def self.url_prefix
+ (@url_prefix.nil? || @url_prefix.empty?) ? '' : @url_prefix + '/'
+ end
end
end
@@ -19,6 +19,16 @@
end
end
+context "With append-prefix option on GET to /overview" do
+ reverse_proxy_prefix = 'proxy_site/resque'
+ Resque::Server.url_prefix = reverse_proxy_prefix
+ setup { get "/overview" }
+
+ test "should contain reverse proxy prefix for asset urls and links" do
+ assert last_response.body.include?(reverse_proxy_prefix)
+ end
+end
+
# Working jobs
context "on GET to /working" do
setup { get "/working" }

0 comments on commit bf34140

Please sign in to comment.