Skip to content

Instantly share code, notes, and snippets.

@Nyoho
Last active August 29, 2015 14:06
Show Gist options
  • Save Nyoho/bd7dae98574e7c3e43bf to your computer and use it in GitHub Desktop.
Save Nyoho/bd7dae98574e7c3e43bf to your computer and use it in GitHub Desktop.
desc "Prints out your Rack middleware stack"
task :middleware do
require 'rack'
options = { config: "config.ru", environment: ENV["RACK_ENV"] || "development" }
app = Rack::Server.new(options).send(:wrapped_app)
app.tap do |mw|
while mw
if mw.class == Class #&& mw.superclass == Sinatra::Base
puts "--- (#{mw} within) ---"
mw = mw.new
end
puts mw.class
# mw = mw.is_a?(Sinatra::ExtendedRack) ? mw.app : mw.instance_variable_get("@app")
mw = mw.instance_variable_get("@app")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment