diff --git a/app/controllers/health_check_controller.rb b/app/controllers/health_check_controller.rb new file mode 100644 index 00000000..432d2443 --- /dev/null +++ b/app/controllers/health_check_controller.rb @@ -0,0 +1,5 @@ +class HealthCheckController < ApplicationController + def index + render json: { status: 'ok' } + end +end diff --git a/config/environments/production.rb b/config/environments/production.rb index 7d140d82..8c0e6a9e 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -37,6 +37,12 @@ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. config.force_ssl = true + config.ssl_options = { + redirect: { + exclude: ->(request) { request.path.include?('health_check') } + } + } + # Log to STDOUT by default config.logger = ActiveSupport::Logger.new(STDOUT) .tap { |logger| logger.formatter = ::Logger::Formatter.new } @@ -84,4 +90,8 @@ ENV.fetch('ALLOWED_HOST_DOMAINS', '').split(',').each do |application_domain| config.hosts << application_domain end + + config.host_authorization = { + exclude: ->(request) { request.path.include?('health_check') } + } end diff --git a/config/routes.rb b/config/routes.rb index 9aed8017..5f0bbf34 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,7 @@ get '/cookie-settings', to: 'home#cookie_settings' get '/cookie-settings/update', to: 'home#update_cookie_settings' get '/cookie-policy', to: 'home#cookie_policy' + get '/health_check', to: 'health_check#index' # API endpoints here namespace :api do diff --git a/spec/controllers/health_check_controller_spec.rb b/spec/controllers/health_check_controller_spec.rb new file mode 100644 index 00000000..8e8baa12 --- /dev/null +++ b/spec/controllers/health_check_controller_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +RSpec.describe HealthCheckController do + describe 'GET #index' do + it 'returns a JSON response with status ok' do + get :index + + expect(response).to have_http_status(:success) + expect(response.content_type).to eq('application/json; charset=utf-8') + + json_response = response.parsed_body + expect(json_response).to eq({ 'status' => 'ok' }) + end + end +end