Class: Rack::Maintenance
- Inherits:
-
Object
- Object
- Rack::Maintenance
- Defined in:
- lib/rack/maintenance.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Maintenance
constructor
A new instance of Maintenance.
Constructor Details
#initialize(app, options = {}) ⇒ Maintenance
Returns a new instance of Maintenance.
3 4 5 6 |
# File 'lib/rack/maintenance.rb', line 3 def initialize(app, ={}) @app = app @domain = [:domain] end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rack/maintenance.rb', line 8 def call(env) case env["PATH_INFO"] when '/maintenance' env["MAINTENANCE"] = true @app.call(env) when "/private/#{ENV['MAINTENANCE_CODE']}" headers = {} Rack::Utils.(headers, :maintenance, { value: ENV['MAINTENANCE_CODE'], expires: 1.week.from_now, path: '/', domain: ".#{@domain}" }) [302, headers.merge('Location' => '/'), ['Redirected to /']] else request = ActionDispatch::Request.new(env) if request.[:maintenance] == ENV['MAINTENANCE_CODE'] || env['HTTP_HOST'] == "admin.#{@domain}" || env['HTTP_HOST'] == "api.#{@domain}" || env['REQUEST_METHOD'] != 'GET' @app.call(env) else [302, {'Location' => '/maintenance'}, ['Redirected to /maintenance']] end end end |