docbrown/app/controllers/api/v0/health_checks_controller.rb
Michael Kohl 6dfabd578f
Rename SiteConfig to Settings::General (#13573)
* Rename SiteConfig

* More renaming

* Update spec

* Update mandatory settings mapping

* More renaming

* e2e test fixes

* You have a rename, and you have a rename

* Spec fix

* More changes

* Temporarily disable specs

* After-merge update

* Undo rename for migration

* undo rename of DUS

* Fix DUS

* Fix merge problem

* Remove redundant DUS

* Fix specs

* Remove unused code

* Change wrong class name

* More cleanup

* Re-add missing values to constant

* Fix constant

* Fix spec

* Remove obsolete fields

* Add accidentally removed field

* Update spec

* Move methods from Settings::General to ForemInstance

* Remove unneeded model

* Change mentions of 'site config'
2021-05-21 14:45:37 +02:00

50 lines
1.2 KiB
Ruby

module Api
module V0
class HealthChecksController < ApiController
before_action :authenticate_with_token
def app
render json: { message: "App is up!" }, status: :ok
end
def database
if ActiveRecord::Base.connected?
render json: { message: "Database connected" }, status: :ok
else
render json: { message: "Database NOT connected!" }, status: :internal_server_error
end
end
def cache
if all_cache_instances_connected?
render json: { message: "Redis connected" }, status: :ok
else
render json: { message: "Redis NOT connected!" }, status: :internal_server_error
end
end
private
def authenticate_with_token
return if request.local?
key = request.headers["health-check-token"]
return if key == Settings::General.health_check_token
error_unauthorized
end
def all_cache_instances_connected?
[
ENV["REDIS_URL"],
ENV["REDIS_SESSIONS_URL"],
ENV["REDIS_SIDEKIQ_URL"],
ENV["REDIS_RPUSH_URL"],
].compact.all? do |url|
Redis.new(url: url).ping == "PONG"
end
end
end
end
end