-
Notifications
You must be signed in to change notification settings - Fork 19
/
application_base_controller.rb
57 lines (47 loc) · 1.3 KB
/
application_base_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true
class ApplicationBaseController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
include TrackRequestId
force_ssl if: :ssl_enabled?
before_action :check_out_of_service
before_action :strict_transport_security
def unauthorized
respond_to do |format|
format.html do
render layout: "application", status: :forbidden
end
format.json do
render json: {
errors: ["Unauthorized"]
}, status: :forbidden
end
end
end
def info_for_paper_trail
{ request_id: request.uuid }
end
private
def check_out_of_service
render "out_of_service", layout: "application" if Rails.cache.read("out_of_service")
end
def ssl_enabled?
Rails.env.production?
end
def strict_transport_security
response.headers["Strict-Transport-Security"] = "max-age=31536000; includeSubDomains" if request.ssl?
end
def not_found
respond_to do |format|
format.html do
render "errors/404", layout: "application", status: :not_found
end
format.json do
render json: {
errors: ["Response not found"]
}, status: :not_found
end
end
end
end