lib/invoker/power/balancer.rb in invoker-1.0.3 vs lib/invoker/power/balancer.rb in invoker-1.0.4
- old
+ new
@@ -40,10 +40,11 @@
end
end
class Balancer
attr_accessor :connection, :http_parser, :session
+ DEV_MATCH_REGEX = /([\w-]+)\.dev(\:\d+)?$/
def self.run(options = {})
EventMachine.start_server('0.0.0.0', Invoker::CONFIG.http_port,
BalancerConnection, options) do |connection|
balancer = Balancer.new(connection)
@@ -108,12 +109,16 @@
end
@backend_data = false
connection.close_connection_after_writing() if backend == session
end
+ def extract_host_from_domain(host)
+ host.match(DEV_MATCH_REGEX)
+ end
+
private
def select_backend_config(host)
- matching_string = host.match(/(\w+)\.dev(\:\d+)?$/)
+ matching_string = extract_host_from_domain(host)
return nil unless matching_string
if selected_app = matching_string[1]
Invoker::CONFIG.process(selected_app)
else
nil