consign 0.1.1 → 0.1.2
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 +4 -4
- data/lib/consign/railtie.rb +15 -1
- data/lib/consign/tunnel.rb +24 -3
- data/lib/consign/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2af068522055eed10550a052dedbe29953fb40fab23ff4dba2cf1c42291de934
|
|
4
|
+
data.tar.gz: 239717958e5d89627c3afd6d969f5d366cf2845de928dccf09596c21760974c5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 48d13d19846e93b95b618a89c9acd89fe41115f5c041ec44aec93f77d2781c7e2ed33a3d0e2dc6644afa8127498029c1e80d04a8dcf8a381b3de95b942012e9a
|
|
7
|
+
data.tar.gz: 6800434ea9b2d0bc7d555cf28bb076f880ab015922a78d585989593ebc20066f915df8a52fee2d72f1c9965244bfc61a6df8bec5e335779c1e94766d7ead10b0
|
data/lib/consign/railtie.rb
CHANGED
|
@@ -2,9 +2,23 @@ module Consign
|
|
|
2
2
|
class Railtie < ::Rails::Railtie
|
|
3
3
|
config.before_configuration do
|
|
4
4
|
Consign.api_key = ENV["CONSIGN_API_KEY"]
|
|
5
|
+
end
|
|
5
6
|
|
|
7
|
+
initializer "consign.hosts_and_settings" do |app|
|
|
6
8
|
host = Consign.local_mode ? ".lvh.me" : ".consign.dev"
|
|
7
|
-
|
|
9
|
+
app.config.hosts << host
|
|
10
|
+
|
|
11
|
+
if Rails.env.development?
|
|
12
|
+
# Allow Action Cable from subdomains
|
|
13
|
+
cable_origin = Consign.local_mode ? /http:\/\/.*\.lvh\.me/ : /https:\/\/.*\.consign\.dev/
|
|
14
|
+
app.config.action_cable.allowed_request_origins ||= []
|
|
15
|
+
app.config.action_cable.allowed_request_origins << cable_origin
|
|
16
|
+
|
|
17
|
+
# Allow Web Console to render when accessed via tunnel
|
|
18
|
+
if app.config.respond_to?(:web_console)
|
|
19
|
+
app.config.web_console.permissions = "0.0.0.0/0"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
8
22
|
end
|
|
9
23
|
|
|
10
24
|
server do
|
data/lib/consign/tunnel.rb
CHANGED
|
@@ -3,6 +3,7 @@ require "net/http"
|
|
|
3
3
|
require "uri"
|
|
4
4
|
require "json"
|
|
5
5
|
require "openssl"
|
|
6
|
+
require "base64"
|
|
6
7
|
|
|
7
8
|
module Consign
|
|
8
9
|
class Tunnel
|
|
@@ -15,6 +16,7 @@ module Consign
|
|
|
15
16
|
|
|
16
17
|
def initialize(port: nil)
|
|
17
18
|
@local_port = port || ENV.fetch("PORT", "3000").to_i
|
|
19
|
+
@write_mutex = Mutex.new
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
def start
|
|
@@ -104,9 +106,28 @@ module Consign
|
|
|
104
106
|
Thread.new do
|
|
105
107
|
begin
|
|
106
108
|
response = forward_to_local(req)
|
|
107
|
-
|
|
109
|
+
|
|
110
|
+
# Sanitize headers and body for UTF-8 to prevent JSON generation/parsing errors
|
|
111
|
+
headers = response.to_hash.transform_values do |values|
|
|
112
|
+
values.map { |v| v.to_s.force_encoding("UTF-8").scrub }
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
body = response.body.to_s
|
|
116
|
+
is_base64 = false
|
|
117
|
+
|
|
118
|
+
if !body.dup.force_encoding("UTF-8").valid_encoding?
|
|
119
|
+
body = Base64.strict_encode64(body)
|
|
120
|
+
is_base64 = true
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
@write_mutex.synchronize do
|
|
124
|
+
socket.puts({ id: req['id'], status: response.code.to_i, headers: headers, body: body, base64: is_base64 }.to_json)
|
|
125
|
+
end
|
|
108
126
|
rescue StandardError => e
|
|
109
|
-
|
|
127
|
+
log "⚠️ Error handling request #{req['id']}: #{e.message}", :error
|
|
128
|
+
@write_mutex.synchronize do
|
|
129
|
+
socket.puts({ id: req['id'], status: 502, headers: {}, body: "Bad Gateway: #{e.message}" }.to_json)
|
|
130
|
+
end
|
|
110
131
|
end
|
|
111
132
|
end
|
|
112
133
|
end
|
|
@@ -144,7 +165,7 @@ module Consign
|
|
|
144
165
|
attempts = 0
|
|
145
166
|
begin
|
|
146
167
|
yield
|
|
147
|
-
rescue StandardError
|
|
168
|
+
rescue StandardError
|
|
148
169
|
attempts += 1
|
|
149
170
|
if attempts < max
|
|
150
171
|
sleep RETRY_DELAY
|
data/lib/consign/version.rb
CHANGED