How can I do a health check for a Rails-based app on Render?

Viewed 2351

Render requires a /health endpoint, but when I create this in my app & deploy for the first time, I am unable to deploy because the app cannot boot without the migrations having run first.

it seems that Render.com health check needs the health endpoint to respond OK even before the migrations have run. how can I achieve this?

3 Answers

You can directly write this in routes file

get '/health_check', to: proc { [200, {}, ['success']] }

It will work for you

create file lib/health_check.rb

HealthCheck = Rack::Builder.new do
  use Rack::CommonLogger
  map '/' do
    run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['OK']] }
  end
end

create file config/initializers/health_check.rb

require './lib/health_check.rb'

Then, in your routes.rb file,

  mount HealthCheck, at: "/health"
Related