This repository was archived by the owner on Jul 27, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change 1
1
require 'net/http'
2
+ require 'resolv'
3
+ require 'uri'
2
4
3
5
class ApplicationController < ActionController ::Base
4
6
# Prevent CSRF attacks by raising an exception.
@@ -44,15 +46,21 @@ def health
44
46
end
45
47
46
48
def crystal_addr
47
- crystal_addr = ENV [ "BACKEND_API" ]
48
- # The address will be of the form, http://172.17.0.5:5432, so we add a trailing slash
49
- crystal_addr . sub ( /^http:/ , 'http:' ) + "/crystal"
49
+ expand_url ENV [ "CRYSTAL_URL" ]
50
50
end
51
51
52
52
def backend_addr
53
- backend_addr = ENV [ "BACKEND_API" ]
54
- # The address will be of the form, http://172.17.0.5:5432, so we add a trailing slash
55
- backend_addr . sub ( /^http:/ , 'http:' ) + "/"
53
+ expand_url ENV [ "NODEJS_URL" ]
54
+ end
55
+
56
+ # Resolve the SRV records for the hostname in the URL
57
+ def expand_url ( url )
58
+ uri = URI ( url )
59
+ resolver = Resolv ::DNS . new ( )
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
63
+ uri . to_s
56
64
end
57
65
58
66
before_action :discover_availability_zone
Original file line number Diff line number Diff line change 5
5
port : 3000
6
6
pathPatterns :
7
7
- /*
8
- networkMode : awsvpc
9
8
environment :
10
- BACKEND_API : " http://api.internal.service:80"
9
+ CRYSTAL_URL : " http://ecsdemo-crystal.${_SERVICE_DISCOVERY_NAMESPACE}/crystal"
10
+ NODEJS_URL : " http://ecsdemo-nodejs.${_SERVICE_DISCOVERY_NAMESPACE}/"
You can’t perform that action at this time.
0 commit comments