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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c62636b6885f9f8bff11cae0039659e05ce5808744d52fca7afee29d9616183
4
- data.tar.gz: 73a23bf8e80a50b3d0f1e12d6323887a761aa5eb8ddb0d2d5ed73fbe93e9c562
3
+ metadata.gz: 2af068522055eed10550a052dedbe29953fb40fab23ff4dba2cf1c42291de934
4
+ data.tar.gz: 239717958e5d89627c3afd6d969f5d366cf2845de928dccf09596c21760974c5
5
5
  SHA512:
6
- metadata.gz: b690e81fe0be9e0dc41a213db28dc094f78dd5a209301b0aabae1c3ce65b37cc0c4b0c5a82b0a68e269fa7be4ca06a61821003a547e608f0e649ff01ac877392
7
- data.tar.gz: 5b9f940ceb11132378cd6ded5840a32ce80f015d74019ebd0c6878117f54e15415c8d867b2197030bbfd37b81692ebee14963bd238dd247c841797025c55ea42
6
+ metadata.gz: 48d13d19846e93b95b618a89c9acd89fe41115f5c041ec44aec93f77d2781c7e2ed33a3d0e2dc6644afa8127498029c1e80d04a8dcf8a381b3de95b942012e9a
7
+ data.tar.gz: 6800434ea9b2d0bc7d555cf28bb076f880ab015922a78d585989593ebc20066f915df8a52fee2d72f1c9965244bfc61a6df8bec5e335779c1e94766d7ead10b0
@@ -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
- Rails.application.config.hosts << host
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
@@ -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
- socket.puts({ id: req['id'], status: response.code.to_i, headers: response.to_hash, body: response.body }.to_json)
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
- socket.puts({ id: req['id'], status: 502, headers: {}, body: "Bad Gateway: #{e.message}" }.to_json)
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 => e
168
+ rescue StandardError
148
169
  attempts += 1
149
170
  if attempts < max
150
171
  sleep RETRY_DELAY
@@ -1,3 +1,3 @@
1
1
  module Consign
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: consign
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Consign Team