Skip to content

Instantly share code, notes, and snippets.

@jcasts
Created January 30, 2014 17:00
Show Gist options
  • Save jcasts/8713375 to your computer and use it in GitHub Desktop.
Save jcasts/8713375 to your computer and use it in GitHub Desktop.
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