Skip to content

Commit

Permalink
Merge pull request #11 from samtgarson/handle-timeout
Browse files Browse the repository at this point in the history
Handle a timeout to the renderer
  • Loading branch information
samtgarson authored May 14, 2017
2 parents 9a37f70 + 128c5af commit e45055b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lib/vueport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ def config
server_port: 5000,
server_config_file: 'config/vueport/webpack.server.conf',
client_config_file: 'config/vueport/webpack.prod.conf',
ssr_enabled: false
ssr_enabled: false,
ssr_timeout: 3
}
end

def configure(&_block)
def configure(&_)
yield config if block_given?
end
end
Expand Down
8 changes: 7 additions & 1 deletion lib/vueport/node_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ def render
end

def response
@response ||= http.post path, content, 'Content-Type' => 'text/plain'
@response ||= http
.tap { |http| http.read_timeout = timeout }
.post path, content, 'Content-Type' => 'text/plain'
end

def http
@http ||= Net::HTTP.new Vueport.config[:server_host], Vueport.config[:server_port]
end

def timeout
Vueport.config[:ssr_timeout] || 3
end
end
end
6 changes: 3 additions & 3 deletions lib/vueport/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def template

def ssr_content
Vueport::NodeClient.new(wrapper(content), path: path).run!
rescue Vueport::RenderError
rescue
wrapper
end

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

def ssr_enabled?
Expand Down
2 changes: 1 addition & 1 deletion lib/vueport/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Vueport
VERSION = '0.1.4'.freeze
VERSION = '0.1.5'.freeze
end
9 changes: 9 additions & 0 deletions spec/vueport/renderer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@

it_behaves_like 'a basic renderer'
end

context 'and node times out' do
before do
allow(Vueport::NodeClient).to receive(:new).and_call_original
allow_any_instance_of(Net::HTTP).to receive(:post).and_raise(Net::ReadTimeout)
end

it_behaves_like 'a basic renderer'
end
end
end

Expand Down

0 comments on commit e45055b

Please sign in to comment.