Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

init

  • Loading branch information...
commit 0a7e6f2189b957c6a3b927f2f9a164d60e20bb6a 0 parents
Adam Wiggins authored December 20, 2010
7  example/config.ru
... ...
@@ -0,0 +1,7 @@
  1
+require File.dirname(__FILE__) + '/../lib/rack/maintenance'
  2
+
  3
+use Rack::Maintenance, [503, {'Content-Type'=>'text/plain'}, StringIO.new("Maintenance mode on!\n")]
  4
+
  5
+app = lambda { |env| [200, {'Content-Type'=>'text/plain'}, StringIO.new("If you're seeing this, maintenance mode is turned off and the app is serving pages normally\n")] }
  6
+
  7
+run app
22  lib/rack/maintenance.rb
... ...
@@ -0,0 +1,22 @@
  1
+module Rack
  2
+  class Maintenance
  3
+    DEFAULT_RESPONSE = [
  4
+      422,
  5
+      { "Content-Type" => "text/html" },
  6
+      "<body><h2>We are undergoing maintenance right now, please try again later.</h2></body></html>"
  7
+    ]
  8
+
  9
+    def initialize(app, maintenance_response=DEFAULT_RESPONSE)
  10
+      @app = app
  11
+      @maintenance_response = maintenance_response
  12
+    end
  13
+
  14
+    def call(env)
  15
+      if ENV['MAINTENANCE'] == 'on'
  16
+        @maintenance_response
  17
+      else
  18
+        @app.call(env)
  19
+      end
  20
+    end
  21
+  end
  22
+end
25  readme.md
Source Rendered
... ...
@@ -0,0 +1,25 @@
  1
+Simple maintenance mode inserted into your app.  Enable with a the MAINTENANCE env var.
  2
+
  3
+# Usage in your rackup file
  4
+
  5
+    require 'lib/rack/maintenance'
  6
+    use Rack::Maintenance
  7
+
  8
+Or provide your own response:
  9
+
  10
+    require 'lib/rack/maintenance'
  11
+    use Rack::Maintenance, [503,{'Content-Type'=>'text/html'}, File.read('public/maintenance.html')]
  12
+
  13
+# Running the example
  14
+
  15
+With maintenance mode off:
  16
+
  17
+    $ cd example
  18
+    $ rackup config.ru
  19
+    $ curl http://localhost:9292
  20
+    If you're seeing this, maintenance mode is turned off and the app is serving pages normally
  21
+
  22
+    $ MAINTENANCE=on rackup config.ru
  23
+    $ curl http://localhost:9292
  24
+    Maintenance mode on!
  25
+

0 notes on commit 0a7e6f2

Please sign in to comment.
Something went wrong with that request. Please try again.