Skip to content
This repository was archived by the owner on Jul 27, 2021. It is now read-only.

Commit 4662262

Browse files
committed
update approach to appending suffix
1 parent b0fa225 commit 4662262

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

app/controllers/application_controller.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,21 @@ def nodejs_uri
5656
# Resolve the SRV records for the hostname in the URL
5757
def expand_url(url)
5858
uri = URI(url)
59-
resolver = Resolv::DNS.new(:search => [ENV["_SERVICE_DISCOVERY_NAME"]])
60-
srv = resolver.getresource("_#{uri.scheme}._tcp.#{uri.host}", Resolv::DNS::Resource::IN::SRV)
61-
uri.host = srv.target.to_s
62-
uri.port = srv.port.to_s
59+
resolver = Resolv::DNS.new()
60+
61+
# if host is relative, append the service discovery name
62+
host = uri.host.count('.') > 0 ? uri.host : "#{uri.host}.#{ENV["_SERVICE_DISCOVERY_NAME"]}"
63+
64+
# lookup the SRV record and use if found
65+
begin
66+
srv = resolver.getresource("_#{uri.scheme}._tcp.#{host}", Resolv::DNS::Resource::IN::SRV)
67+
uri.host = srv.target.to_s
68+
uri.port = srv.port.to_s
69+
rescue => e
70+
logger.error e.message
71+
logger.error e.backtrace.join("\n")
72+
end
73+
6374
logger.info "expanded #{url} to #{uri}"
6475
uri
6576
end

0 commit comments

Comments
 (0)