ruby_native 0.9.3 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bea37c1e721c525bee3535c67771d53969d46eca1458cbdf3948c5b6cb7c1bcc
4
- data.tar.gz: 63963d9b8707c01862cc9a603e0a26baf8ae91eb4f84a84404c955b1a1e0742b
3
+ metadata.gz: 56ba510fa3e0b1a2584a3aeaf4aede167043a3772c31ff8c08ab968dfac94ab5
4
+ data.tar.gz: ab47c472e8537a3204388ddd610d1a0d93417507e450c353a89ce9a6b5ee5af1
5
5
  SHA512:
6
- metadata.gz: 0e97a991d0bc54079de18af9be52f4bc7e3df3e57229047a1c424e7ea89329db48a1d8f3715cd3cdd37ef026afbc01185985192fc6d7dabf7d3d7d8ea869237b
7
- data.tar.gz: 31c81f18e641df0c60f6b1f97e3c5f8086dd7f9962353655b71a3fb935050e3be8853491c1a4b0fae0af55371ba10fab566fb5d66ef23f1e6dd98af6ae21e919
6
+ metadata.gz: 39844845a2983578185ce85e2c0213092467801f9135b5681515b9ee495770a875ccac8ba2c1bf2ae39c8b8952ec5cf3118fe36661ff6a602a450f0aa97a2430
7
+ data.tar.gz: f0bf80917cae40af6f92ca71c644dd20839aa899fedcb0c9455c01a7b3549963bc78490594a4532fc67d951bfc49217938a5275eb289122965b59b174c89b7dc
@@ -13,36 +13,44 @@ module RubyNative
13
13
  PUBLIC_NAMESERVERS = ["1.1.1.1", "8.8.8.8"].freeze
14
14
 
15
15
  def initialize(argv)
16
+ @url = parse_option(argv, "--url")
16
17
  @port = parse_port(argv)
18
+ @upstream = @url || "http://localhost:#{@port}"
17
19
  end
18
20
 
19
21
  def run
20
22
  check_cloudflared!
21
- check_local_server!
23
+ check_upstream!
22
24
  start_tunnel
23
25
  end
24
26
 
25
27
  private
26
28
 
27
- def check_local_server!
28
- uri = URI("http://localhost:#{@port}#{CONFIG_PATH}")
29
+ def check_upstream!
30
+ uri = URI("#{@upstream}#{CONFIG_PATH}")
29
31
  response = fetch_config_response(uri)
30
32
 
31
33
  return if response.is_a?(Net::HTTPSuccess)
32
34
 
33
- puts "Rails server is running on port #{@port}, but #{CONFIG_PATH} returned #{response.code}."
35
+ puts "Rails server is reachable at #{@upstream}, but #{CONFIG_PATH} returned #{response.code}."
34
36
  puts ""
35
37
  puts "Make sure the ruby_native gem is installed and mounted:"
36
38
  puts " https://rubynative.com/docs/install"
37
39
  exit 1
38
40
  rescue Errno::ECONNREFUSED
39
- puts "Nothing is running on port #{@port}."
40
- puts ""
41
- puts "Start your Rails server in another terminal:"
42
- puts " bin/rails server -p #{@port}"
41
+ if @url
42
+ puts "Could not connect to #{@url}."
43
+ puts ""
44
+ puts "Make sure your Rails server is reachable at that URL."
45
+ else
46
+ puts "Nothing is running on port #{@port}."
47
+ puts ""
48
+ puts "Start your Rails server in another terminal:"
49
+ puts " bin/rails server -p #{@port}"
50
+ end
43
51
  exit 1
44
52
  rescue => e
45
- puts "Could not reach http://localhost:#{@port}#{CONFIG_PATH}: #{e.message}"
53
+ puts "Could not reach #{@upstream}#{CONFIG_PATH}: #{e.message}"
46
54
  exit 1
47
55
  end
48
56
 
@@ -100,12 +108,13 @@ module RubyNative
100
108
  end
101
109
 
102
110
  def parse_port(argv)
103
- index = argv.index("--port")
104
- if index
105
- argv[index + 1]&.to_i || 3000
106
- else
107
- 3000
108
- end
111
+ value = parse_option(argv, "--port")
112
+ value ? value.to_i : 3000
113
+ end
114
+
115
+ def parse_option(argv, flag)
116
+ index = argv.index(flag)
117
+ index ? argv[index + 1] : nil
109
118
  end
110
119
 
111
120
  def check_cloudflared!
@@ -121,12 +130,16 @@ module RubyNative
121
130
  end
122
131
 
123
132
  def start_tunnel
124
- puts "Starting tunnel to http://localhost:#{@port}..."
125
- puts "Make sure your Rails server is running on port #{@port} in another terminal."
133
+ puts "Starting tunnel to #{@upstream}..."
134
+ if @url
135
+ puts "Make sure your Rails server is reachable at #{@url}."
136
+ else
137
+ puts "Make sure your Rails server is running on port #{@port} in another terminal."
138
+ end
126
139
  puts ""
127
140
 
128
141
  stdin, stdout_err, wait_thread = Open3.popen2e(
129
- "cloudflared", "tunnel", "--url", "http://localhost:#{@port}"
142
+ "cloudflared", "tunnel", "--url", @upstream
130
143
  )
131
144
  stdin.close
132
145
 
@@ -175,7 +188,11 @@ module RubyNative
175
188
  puts url
176
189
  puts ""
177
190
  puts "Scan the QR code or paste the URL into the Ruby Native Preview app."
178
- puts "Keep this running and your Rails server on port #{@port} in another terminal."
191
+ if @url
192
+ puts "Keep this running and your Rails server reachable at #{@url}."
193
+ else
194
+ puts "Keep this running and your Rails server on port #{@port} in another terminal."
195
+ end
179
196
  puts "Press Ctrl+C to stop."
180
197
  end
181
198
 
@@ -1,3 +1,3 @@
1
1
  module RubyNative
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_native
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Masilotti