Created
January 30, 2014 17:00
-
-
Save jcasts/8713375 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyAppMiddleware | |
PATH_MATCHER = %r{^/app} | |
def initialize app | |
@app = app | |
end | |
def call env | |
if env['PATH_INFO'] =~ PATH_MATCHER | |
do_thing | |
else | |
@app.call(env) | |
end | |
end | |
def build_response status, body | |
body = [body] unless body.respond_to?(:each) | |
[status, {'Content-Length' => '', 'Content-Type' => ''}, body] | |
end | |
def do_thing | |
build_response() | |
rescue => e | |
build_response(500, "Something bad happened") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment