diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c4ea5d6..f77ec62 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,14 +2,4 @@ class ApplicationController < ActionController::API include ActionController::MimeResponds include ActionController::ImplicitRender - before_action :require_authorization_token - - private - - def require_authorization_token - token = request.headers["Authorization"]&.split(" ")&.at(1) - unless AuthToken.exists?(token: token) - render json: {}, status: 401 - end - end end diff --git a/app/controllers/monitoring_controller.rb b/app/controllers/monitoring_controller.rb new file mode 100644 index 0000000..c0a52a7 --- /dev/null +++ b/app/controllers/monitoring_controller.rb @@ -0,0 +1,5 @@ +class MonitoringController < ApplicationController + def live + head :ok + end +end diff --git a/app/controllers/v1/loans_controller.rb b/app/controllers/v1/loans_controller.rb index f53051a..c1c82de 100644 --- a/app/controllers/v1/loans_controller.rb +++ b/app/controllers/v1/loans_controller.rb @@ -1,5 +1,5 @@ module V1 - class LoansController < ApplicationController + class LoansController < V1Controller def index user = User.find(params[:user_uniqname]) rescue diff --git a/app/controllers/v1/users_controller.rb b/app/controllers/v1/users_controller.rb index 12ffffe..5bd44eb 100644 --- a/app/controllers/v1/users_controller.rb +++ b/app/controllers/v1/users_controller.rb @@ -1,5 +1,5 @@ module V1 - class UsersController < ApplicationController + class UsersController < V1Controller def show @user = User.find(params[:uniqname]) rescue diff --git a/app/controllers/v1_controller.rb b/app/controllers/v1_controller.rb new file mode 100644 index 0000000..c16e1c2 --- /dev/null +++ b/app/controllers/v1_controller.rb @@ -0,0 +1,12 @@ +class V1Controller < ApplicationController + before_action :require_authorization_token + + private + + def require_authorization_token + token = request.headers["Authorization"]&.split(" ")&.at(1) + unless AuthToken.exists?(token: token) + render json: {}, status: 401 + end + end +end diff --git a/config/routes.rb b/config/routes.rb index 3c124a1..74ccfe8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,4 +5,5 @@ get "/loans/download", to: "loans#download" end end + get "/-/live", to: "monitoring#live" end diff --git a/spec/requests/monitoring_spec.rb b/spec/requests/monitoring_spec.rb new file mode 100644 index 0000000..a1bc36c --- /dev/null +++ b/spec/requests/monitoring_spec.rb @@ -0,0 +1,7 @@ +require "rails_helper" +describe "get /-/live", type: :request do + it "show OK" do + get "/-/live" + expect(response).to have_http_status(:success) + end +end