Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a cli option to specify backend services host if they are not running locally #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/invoker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module Invoker
class << self
attr_accessor :config, :tail_watchers, :commander
attr_accessor :dns_cache, :daemonize
attr_accessor :backend_host

alias_method :daemonize?, :daemonize

Expand Down
5 changes: 5 additions & 0 deletions lib/invoker/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ def uninstall
type: :boolean,
banner: "Daemonize the server into the background",
aliases: [:d]
option :backend_host,
type: :string,
banner: "Host to be used for backend services if they are not running locally. e.g. docker container services in Mac OS X",
aliases: [:h]
def start(file)
Invoker.setup_config_location
port = options[:port] || 9000
Invoker.daemonize = options[:daemon]
Invoker.backend_host = options[:backend_host]
Invoker.load_invoker_config(file, port)
warn_about_terminal_notifier
warn_about_old_configuration
Expand Down
6 changes: 5 additions & 1 deletion lib/invoker/power/balancer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def headers_received(headers)

dns_check_response = UrlRewriter.new.select_backend_config(headers['Host'])
if dns_check_response && dns_check_response.port
connection.server(session, host: '0.0.0.0', port: dns_check_response.port)
connection.server(session, host: backend_host, port: dns_check_response.port)
else
return_error_page(404)
http_parser.reset
Expand Down Expand Up @@ -105,6 +105,10 @@ def frontend_disconnect(backend, name)
connection.close_connection_after_writing if backend == session
end

def backend_host
Invoker.backend_host || '0.0.0.0'
end

private

def return_error_page(status)
Expand Down
12 changes: 12 additions & 0 deletions spec/invoker/power/balancer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,16 @@
@balancer.headers_received(headers)
end
end

describe "#backend_host" do
it "should return localhost as default when backend host is not configured" do
Invoker.backend_host = nil
expect(@balancer.backend_host).to eql("0.0.0.0")
end

it "should return as per configured backend host" do
Invoker.backend_host = "192.168.59.103"
expect(@balancer.backend_host).to eql("192.168.59.103")
end
end
end