Issue using insert_after/before “ActionDispatch::Static”

We are currently building a new product on Rails 3 with a couple custom middleware rack apps. Everything is working great on development and we’re progressing nicely. Today I decided to start setting up the production environment and the following error popped up:

No such middleware to insert after: "ActionDispatch::Static"

I had this in my config/application.rb:

config.middleware.insert_after('ActionDispatch::Static', '::API::Throttle')

I received this error while trying to run rake or startup unicorn. After looking around trying to figure out what I was doing wrong I discovered this in the production config.

config.serve_static_assets = false

Essentially what this does is remove “ActionDispatch::Static” from the rails middleware stack. I had no idea that I could not rely on that being there.

Solution, use insert_before ‘Rack::Lock’ instead:

config.middleware.insert_before('Rack::Lock', '::API::Throttle')

Hope this saves someone some time!