lib/sitehub/builder.rb in sitehub-0.4.8 vs lib/sitehub/builder.rb in sitehub-0.4.9
- old
+ new
@@ -20,15 +20,18 @@
@force_ssl = true
@ssl_exclusions = except
end
def initialize(&block)
- @forward_proxies = ForwardProxies.new
@reverse_proxies = {}
instance_eval(&block) if block
end
+ def forward_proxies
+ @forward_proxies ||= ForwardProxies.new(sitehub_cookie_name)
+ end
+
def build
forward_proxies.init
add_default_middleware
middlewares.reverse!
apply_middleware(forward_proxies)
@@ -43,20 +46,14 @@
use Rack::FiberPool
use Rack::SslEnforcer, except: @ssl_exclusions if @force_ssl
end
def proxy(opts = {}, &block)
- if opts.is_a?(Hash)
- mapped_path, url = *opts.to_a.flatten
- else
- mapped_path = opts
- url = nil
- end
+ mapped_path, url = *(opts.respond_to?(:to_a) ? opts.to_a : [opts]).flatten
- forward_proxies << ForwardProxyBuilder.new(sitehub_cookie_name: sitehub_cookie_name,
- url: url,
- mapped_path: mapped_path,
- &block)
+ forward_proxies.add_proxy(url: url,
+ mapped_path: mapped_path,
+ &block)
end
def reverse_proxy(hash)
reverse_proxies.merge!(hash)
end