* API Articles v0-v1 restructure * Remove unused helper * Bulk move API controllers into concerns + add V1 controllers * Extract API routes + some fixes * Fix v1 api_controller authenticate! + add more article_controller specs * Completed spec/requests/api/v1/articles_spec.rb * specs up to listings * All v1 specs except for 9 skips * mime_types cleanup + authenticate! relocation Co-authored-by: Fernando Valverde <fernando@visualcosita.com>
50 lines
1.4 KiB
Ruby
50 lines
1.4 KiB
Ruby
module Api
|
|
module HealthChecksController
|
|
extend ActiveSupport::Concern
|
|
|
|
def app
|
|
render json: { message: I18n.t("api.v0.health_checks_controller.app_is_up") }, status: :ok
|
|
end
|
|
|
|
def database
|
|
if ActiveRecord::Base.connected?
|
|
render json: { message: I18n.t("api.v0.health_checks_controller.database_connected") }, status: :ok
|
|
else
|
|
render json: { message: I18n.t("api.v0.health_checks_controller.database_not_connected") },
|
|
status: :internal_server_error
|
|
end
|
|
end
|
|
|
|
def cache
|
|
if all_cache_instances_connected?
|
|
render json: { message: I18n.t("api.v0.health_checks_controller.redis_connected") }, status: :ok
|
|
else
|
|
render json: { message: I18n.t("api.v0.health_checks_controller.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.fetch("REDIS_URL", nil),
|
|
ENV.fetch("REDIS_SESSIONS_URL", nil),
|
|
ENV.fetch("REDIS_SIDEKIQ_URL", nil),
|
|
ENV.fetch("REDIS_RPUSH_URL", nil),
|
|
].compact.all? do |url|
|
|
Redis.new(url: url).ping == "PONG"
|
|
end
|
|
end
|
|
end
|
|
end
|