diff options
author | John Keiser <jkeiser@opscode.com> | 2014-06-02 14:56:35 -0700 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2014-06-02 14:56:35 -0700 |
commit | a1d5a5d147afad5aa41c99e1b00ce0f543c33dae (patch) | |
tree | 0915a339b81e83b9bbf426ec2f8f71caacec021f /lib/chef_zero/server.rb | |
parent | 9a1500be6d98828454a740c77403f1b3e74e28ed (diff) | |
download | chef-zero-a1d5a5d147afad5aa41c99e1b00ce0f543c33dae.tar.gz |
Honor :single_org => 'orgname' parameter everywhere
Diffstat (limited to 'lib/chef_zero/server.rb')
-rw-r--r-- | lib/chef_zero/server.rb | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb index e279441..4955282 100644 --- a/lib/chef_zero/server.rb +++ b/lib/chef_zero/server.rb @@ -386,35 +386,42 @@ module ChefZero router.not_found = NotFoundEndpoint.new if options[:single_org] - rest_base_prefix = [ 'organizations', 'chef' ] + rest_base_prefix = [ 'organizations', options[:single_org] ] else rest_base_prefix = [] end return proc do |env| - request = RestRequest.new(env, rest_base_prefix) - if @on_request_proc - @on_request_proc.call(request) - end - response = nil - if @request_handler - response = @request_handler.call(request) - end - unless response - response = router.call(request) - end - if @on_response_proc - @on_response_proc.call(request, response) - end + begin + request = RestRequest.new(env, rest_base_prefix) + if @on_request_proc + @on_request_proc.call(request) + end + response = nil + if @request_handler + response = @request_handler.call(request) + end + unless response + response = router.call(request) + end + if @on_response_proc + @on_response_proc.call(request, response) + end - # Insert Server header - response[1]['Server'] = 'chef-zero' + # Insert Server header + response[1]['Server'] = 'chef-zero' - # Puma expects the response to be an array (chunked responses). Since - # we are statically generating data, we won't ever have said chunked - # response, so fake it. - response[-1] = Array(response[-1]) + # Puma expects the response to be an array (chunked responses). Since + # we are statically generating data, we won't ever have said chunked + # response, so fake it. + response[-1] = Array(response[-1]) - response + response + rescue + if options[:log_level] == :debug + STDERR.puts "Request Error: #{$!}" + STDERR.puts $!.backtrace.join("\n") + end + end end end |