rstacruz / sinatra-assetpack

Package your assets transparently in Sinatra.
http://ricostacruz.com/sinatra-assetpack/
MIT License
542 stars 96 forks source link

Catch-all routes break assetpack #13

Closed christianhellsten closed 13 years ago

christianhellsten commented 13 years ago

I have a catch-all route:

get '/*' do
# xxx
end

This breaks requests to http://localhost/css/application.css, which are routed to the catch-all method instead of assetpack. http://localhost/js/application.js works…

rstacruz commented 13 years ago

There are two ways you can remedy this.

One way is to declare your catchall route after the assets block.

class App
  assets do
    css :foo, [ '/css/bar.css', ... ]
  end

  get '/*' do
    do_stuff
  end
end

or use Sinatra's pass to stop processing the catch-all route when it's something that it shouldn't handle.

class App
  get '/*' do
    pass unless valid?
    do_stuff
  end

  assets do
    css :foo, [ '/css/bar.css', ... ]
  end
end

I don't think there's a way for AssetPack to make a workaround for this as there's no way to define route priorities in Sinatra other than definition order.