-
-
Save excid3/2d8a791f123614edeb6708e8ac087455 to your computer and use it in GitHub Desktop.
Middleware to support prefixed value in the url
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 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