hatamo commited on
Commit
0850793
·
1 Parent(s): 3567b1b

Optimize health check endpoints for Hugging Face Spaces

Browse files
app/controllers/health_controller.rb CHANGED
@@ -1,5 +1,17 @@
1
  class HealthController < ActionController::API
 
 
2
  def up
3
- render json: { status: 'ok' }, status: :ok
 
 
 
 
 
 
 
 
 
 
4
  end
5
  end
 
1
  class HealthController < ActionController::API
2
+ skip_before_action :verify_authenticity_token, if: :json_request?
3
+
4
  def up
5
+ render json: { status: 'ok', timestamp: Time.current.iso8601 }, status: :ok
6
+ end
7
+
8
+ def health
9
+ render json: { status: 'healthy' }, status: :ok
10
+ end
11
+
12
+ private
13
+
14
+ def json_request?
15
+ request.format.json?
16
  end
17
  end
config/environments/production.rb CHANGED
@@ -108,4 +108,10 @@ Rails.application.configure do
108
  #
109
  # Skip DNS rebinding protection for the default health check endpoint.
110
  # config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
 
 
 
 
 
 
111
  end
 
108
  #
109
  # Skip DNS rebinding protection for the default health check endpoint.
110
  # config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
111
+
112
+ # Hugging Face Spaces configuration
113
+ # Disable request logging for health checks to speed up startup
114
+ if ENV['HUGGING_FACE_HUB_TOKEN'].present?
115
+ config.middleware.insert_after ActionDispatch::Static, Rack::Timeout, service_timeout: 30
116
+ end
117
  end
config/routes.rb CHANGED
@@ -22,5 +22,8 @@ Rails.application.routes.draw do
22
  end
23
  end
24
 
 
25
  get "up" => "rails/health#show", as: :rails_health_check
 
 
26
  end
 
22
  end
23
  end
24
 
25
+ # Health check endpoints
26
  get "up" => "rails/health#show", as: :rails_health_check
27
+ get "health" => "health#health"
28
+ get "health/up" => "health#up"
29
  end