Browse files

support for a simple /health endpoint

  • Loading branch information...
1 parent f5e01bc commit 4731ce8c24308eb5dbef3a8baad3d4e56568a068 @gorsuch gorsuch committed Mar 12, 2012
Showing with 15 additions and 3 deletions.
  1. +10 −3 lib/taps/server.rb
  2. +5 −0 spec/server_spec.rb
View
13 lib/taps/server.rb
@@ -38,12 +38,19 @@ class Server < Sinatra::Base
end
before do
- major, minor, patch = request.env['HTTP_TAPS_VERSION'].split('.') rescue []
- unless "#{major}.#{minor}" == Taps.compatible_version && patch.to_i >= 23
- halt 417, "Taps >= v#{Taps.compatible_version}.22 is required for this server"
+ unless request.path_info == '/health'
+ major, minor, patch = request.env['HTTP_TAPS_VERSION'].split('.') rescue []
+ unless "#{major}.#{minor}" == Taps.compatible_version && patch.to_i >= 23
+ halt 417, "Taps >= v#{Taps.compatible_version}.22 is required for this server"
+ end
end
end
+ get '/health' do
+ content_type 'application/json'
+ OkJson.encode({ :ok => true })
+ end
+
get '/' do
"hello"
end
View
5 spec/server_spec.rb
@@ -31,5 +31,10 @@ def app
get('/', { }, { 'HTTP_AUTHORIZATION' => @auth_header, 'HTTP_TAPS_VERSION' => '0.0.1' })
last_response.status.should == 417
end
+
+ it "allows healthcheck to be accessed w/o HTTP_TAPS_VERSION" do
+ get('/health', { }, { 'HTTP_AUTHORIZATION' => @auth_header })
+ last_response.status.should == 200
+ end
end

0 comments on commit 4731ce8

Please sign in to comment.