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

Commit d8e9b9c

Browse files
committed
cleanup uri handling
1 parent 122d474 commit d8e9b9c

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

app/controllers/application_controller.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ class ApplicationController < ActionController::Base
1010
# Example endpoint that calls the backend nodejs api
1111
def index
1212
begin
13-
url = URI.parse(backend_addr)
14-
req = Net::HTTP::Get.new(url.to_s)
15-
res = Net::HTTP.start(url.host, url.port) {|http|
13+
req = Net::HTTP::Get.new(nodejs_uri.to_s)
14+
res = Net::HTTP.start(nodejs_uri.host, nodejs_uri.port) {|http|
1615
http.request(req)
1716
}
1817

@@ -22,9 +21,8 @@ def index
2221
@text = "no backend found"
2322
end
2423

25-
crystalurl = URI.parse(crystal_addr)
26-
crystalreq = Net::HTTP::Get.new(crystalurl.to_s)
27-
crystalres = Net::HTTP.start(crystalurl.host, crystalurl.port) {|http|
24+
crystalreq = Net::HTTP::Get.new(crystal_uri.to_s)
25+
crystalres = Net::HTTP.start(crystal_uri.host, crystal_uri.port) {|http|
2826
http.request(crystalreq)
2927
}
3028

@@ -34,7 +32,9 @@ def index
3432
@crystal = "no backend found"
3533
end
3634

37-
rescue
35+
rescue => e
36+
logger.error e.message
37+
logger.error e.backtrace.join("\n")
3838
@text = "no backend found"
3939
@crystal = "no backend found"
4040
end
@@ -45,11 +45,11 @@ def health
4545
render plain: "OK"
4646
end
4747

48-
def crystal_addr
48+
def crystal_uri
4949
expand_url ENV["CRYSTAL_URL"]
5050
end
5151

52-
def backend_addr
52+
def nodejs_uri
5353
expand_url ENV["NODEJS_URL"]
5454
end
5555

@@ -60,7 +60,8 @@ def expand_url(url)
6060
srv = resolver.getresource("_#{uri.scheme}._tcp.#{uri.host}", Resolv::DNS::Resource::IN::SRV)
6161
uri.host = srv.target.to_s
6262
uri.port = srv.port.to_s
63-
uri.to_s
63+
logger.info "expanded #{url} to #{uri}"
64+
uri
6465
end
6566

6667
before_action :discover_availability_zone

0 commit comments

Comments
 (0)