Created
May 10, 2019 15:13
-
-
Save oystersauce8/33a121929be491dbf989606f6d636b6c to your computer and use it in GitHub Desktop.
rack_proxy_example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Gemfile b/Gemfile | |
index edf9fd5..d2bf01e 100644 | |
--- a/Gemfile | |
+++ b/Gemfile | |
@@ -38,3 +38,4 @@ end | |
gem 'padrino', '0.10.6' | |
gem 'rack-jsonp-middleware', :require => 'rack/jsonp' | |
+gem 'rack-proxy' | |
diff --git a/Gemfile.lock b/Gemfile.lock | |
index 02d6c3b..fef6573 100644 | |
--- a/Gemfile.lock | |
+++ b/Gemfile.lock | |
@@ -97,6 +97,8 @@ GEM | |
rack | |
rack-protection (1.3.2) | |
rack | |
+ rack-proxy (0.6.5) | |
+ rack | |
rack-test (0.6.2) | |
rack (>= 1.0) | |
rack-timeout (0.3.2) | |
@@ -163,6 +165,7 @@ DEPENDENCIES | |
puma (= 2.16.0) | |
rack-jsonp-middleware | |
rack-parser | |
+ rack-proxy | |
rack-test | |
rack-timeout (= 0.3.2) | |
rake | |
diff --git a/admin/app.rb b/admin/app.rb | |
index c487e7f..59d49e4 100644 | |
--- a/admin/app.rb | |
+++ b/admin/app.rb | |
@@ -1,6 +1,8 @@ | |
class Admin < Padrino::Application | |
#use Rollbar::Middleware::Sinatra | |
use ActiveRecord::ConnectionAdapters::ConnectionManagement | |
+ use MyProxy, { ssl_verify_none: true, backend: ENV['PROXY_BACKEND'] } | |
+ | |
register Padrino::Rendering | |
register Padrino::Mailer | |
register Padrino::Helpers | |
diff --git a/app/app.rb b/app/app.rb | |
index 1fc522b..05acc9c 100644 | |
--- a/app/app.rb | |
+++ b/app/app.rb | |
@@ -1,6 +1,7 @@ | |
class Mothership < Padrino::Application | |
#use Rollbar::Middleware::Sinatra | |
use ActiveRecord::ConnectionAdapters::ConnectionManagement | |
+ use MyProxy, { ssl_verify_none: true, backend: ENV['PROXY_BACKEND'] } | |
register Padrino::Rendering | |
register Padrino::Mailer | |
diff --git a/lib/my_proxy.rb b/lib/my_proxy.rb | |
new file mode 100644 | |
index 0000000..c9fe9e0 | |
--- /dev/null | |
+++ b/lib/my_proxy.rb | |
@@ -0,0 +1,20 @@ | |
+require 'rack-proxy' | |
+ | |
+class MyProxy < Rack::Proxy | |
+ def perform_request(env) | |
+ #puts "DB8 perform_request(env) #{ENV['PROXY_BACKEND']} #{ENV['PROXY_PATTERN']}" | |
+ request = Rack::Request.new(env) | |
+ if ENV['PROXY_PATTERN'].present? && request.path =~ /^#{ENV['PROXY_PATTERN']}/ | |
+ puts "DB8 Will proxy #{request.path}" | |
+ env["HTTP_HOST"] = URI( ENV['PROXY_BACKEND'] ).host | |
+ super(env) | |
+ else | |
+ #puts "DB8 Will Not proxy" | |
+ @app.call(env) | |
+ end | |
+ end | |
+ | |
+end | |
+ | |
+ | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment