Skip to content

Instantly share code, notes, and snippets.

@excid3
Forked from romaimperator/middleware.rb
Created March 5, 2018 03:14
Show Gist options
  • Save excid3/2d8a791f123614edeb6708e8ac087455 to your computer and use it in GitHub Desktop.
Save excid3/2d8a791f123614edeb6708e8ac087455 to your computer and use it in GitHub Desktop.
Middleware to support prefixed value in the url
class MyMiddleware
def initialize(app)
@app = app
@message = message
end
def call(env)
dup._call(env)
end
def _call(env)
_, script_name, request_path = env['REQUEST_PATH'].split('/', 3)
env['SCRIPT_NAME'] = '/' + script_name
env['PATH_INFO'] = '/' + request_path
env['REQUEST_PATH'] = '/' + request_path
env['REQUEST_URI'] = '/' + request_path
@status, @headers, @response = @app.call(env)
[@status, @headers, self]
end
def each(&block)
@response.each(&block)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment