From 466226218144badfe274abe0adc67e3be8ef2d6b Mon Sep 17 00:00:00 2001 From: Casey Lee Date: Fri, 10 Aug 2018 20:45:30 +0000 Subject: [PATCH] update approach to appending suffix --- app/controllers/application_controller.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 831a102..10afcf0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -56,10 +56,21 @@ def nodejs_uri # Resolve the SRV records for the hostname in the URL def expand_url(url) uri = URI(url) - resolver = Resolv::DNS.new(:search => [ENV["_SERVICE_DISCOVERY_NAME"]]) - srv = resolver.getresource("_#{uri.scheme}._tcp.#{uri.host}", Resolv::DNS::Resource::IN::SRV) - uri.host = srv.target.to_s - uri.port = srv.port.to_s + resolver = Resolv::DNS.new() + + # if host is relative, append the service discovery name + host = uri.host.count('.') > 0 ? uri.host : "#{uri.host}.#{ENV["_SERVICE_DISCOVERY_NAME"]}" + + # lookup the SRV record and use if found + begin + srv = resolver.getresource("_#{uri.scheme}._tcp.#{host}", Resolv::DNS::Resource::IN::SRV) + uri.host = srv.target.to_s + uri.port = srv.port.to_s + rescue => e + logger.error e.message + logger.error e.backtrace.join("\n") + end + logger.info "expanded #{url} to #{uri}" uri end