Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit e45055b

Browse files
authored
Merge pull request #11 from samtgarson/handle-timeout
Handle a timeout to the renderer
2 parents 9a37f70 + 128c5af commit e45055b

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

lib/vueport.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ def config
1212
server_port: 5000,
1313
server_config_file: 'config/vueport/webpack.server.conf',
1414
client_config_file: 'config/vueport/webpack.prod.conf',
15-
ssr_enabled: false
15+
ssr_enabled: false,
16+
ssr_timeout: 3
1617
}
1718
end
1819

19-
def configure(&_block)
20+
def configure(&_)
2021
yield config if block_given?
2122
end
2223
end

lib/vueport/node_client.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,17 @@ def render
2525
end
2626

2727
def response
28-
@response ||= http.post path, content, 'Content-Type' => 'text/plain'
28+
@response ||= http
29+
.tap { |http| http.read_timeout = timeout }
30+
.post path, content, 'Content-Type' => 'text/plain'
2931
end
3032

3133
def http
3234
@http ||= Net::HTTP.new Vueport.config[:server_host], Vueport.config[:server_port]
3335
end
36+
37+
def timeout
38+
Vueport.config[:ssr_timeout] || 3
39+
end
3440
end
3541
end

lib/vueport/renderer.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ def template
2828

2929
def ssr_content
3030
Vueport::NodeClient.new(wrapper(content), path: path).run!
31-
rescue Vueport::RenderError
31+
rescue
3232
wrapper
3333
end
3434

35-
def wrapper(content = '')
36-
content_tag :div, content, id: CONTENT_WRAPPER_ID, 'v-bind:class' => 'wrapperClass'
35+
def wrapper(inner = '')
36+
content_tag :div, inner, id: CONTENT_WRAPPER_ID, 'v-bind:class' => 'wrapperClass'
3737
end
3838

3939
def ssr_enabled?

lib/vueport/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Vueport
2-
VERSION = '0.1.4'.freeze
2+
VERSION = '0.1.5'.freeze
33
end

spec/vueport/renderer_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@
6868

6969
it_behaves_like 'a basic renderer'
7070
end
71+
72+
context 'and node times out' do
73+
before do
74+
allow(Vueport::NodeClient).to receive(:new).and_call_original
75+
allow_any_instance_of(Net::HTTP).to receive(:post).and_raise(Net::ReadTimeout)
76+
end
77+
78+
it_behaves_like 'a basic renderer'
79+
end
7180
end
7281
end
7382

0 commit comments

Comments
 (0)