I am trying to add/append middleware to the stack (in config.ru) on certain requests (where request.path == “/hi”)
I was trying to do that with Rack::Builder
But i seem to fail at it.
Rack::Builder.new do
use added_middleware1
use added_middleware2
end.call(@env) if @request.path == "/something"
I am not sure if that makes my problem clear.
The
@requestvariable should only be available when an actual request is happening, but the code you posted is probably getting run at configuration time when the server starts up. There is example code on the front page of the Rack::Builder documentation showing how to do something like you would want: