Skip to content

Commit

Permalink
Merge pull request #575 from Crown-Commercial-Service/add-healthcheck…
Browse files Browse the repository at this point in the history
…-endpoint

Add the healthcheck endpoint
  • Loading branch information
tim-s-ccs authored Nov 6, 2023
2 parents 1617cc7 + faf84cd commit 9d6dd4b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/health_check_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class HealthCheckController < ApplicationController
def index
render json: { status: 'ok' }
end
end
10 changes: 10 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions spec/controllers/health_check_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9d6dd4b

Please sign in to comment.