Here''s one useful snippet: def (Before="").new(a,*o)Rack::Cascade.new(o<<a)end This means that this app: module App use Before, Rack::File.new(''public'') end Will pass all requests through Rack::File.new(''public'') first, and only proceed to App if that returns 404. This can be very useful for serving static stuff in development mode (Rack::File will serve files from the ''public'' directory if it matches the URL; e.g. ./public/jquery.js will be available at localhost:3301/jquery.js) Maybe we should add it to camping.rb? // Magnus Holm
I think that''s immensely useful. It''ll allow me to keep JS/CSS/HTML separate from the app files but still packaged with the app. Dave On Fri, Dec 16, 2011 at 3:13 PM, Magnus Holm <judofyr at gmail.com> wrote:> Here''s one useful snippet: > > ?def (Before="").new(a,*o)Rack::Cascade.new(o<<a)end > > This means that this app: > > ?module App > ? ?use Before, Rack::File.new(''public'') > ?end > > Will pass all requests through Rack::File.new(''public'') first, and > only proceed to App if that returns 404. This can be very useful for > serving static stuff in development mode (Rack::File will serve files > from the ''public'' directory if it matches the URL; e.g. > ./public/jquery.js will be available at localhost:3301/jquery.js) > > Maybe we should add it to camping.rb? > > // Magnus Holm > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list-- Dave
I usually just use Rack::Static: module App use Rack::Static, :urls => [''/static''] end This would serve ./static/jquery.js at localhost:3301/static/jquery.js, though - with the directory included in URL - but will also serve files from subdirectories recursively (I don''t know if Rack::File does this). -- Matma Rex
2011/12/16 Bartosz Dziewo?ski <matma.rex at gmail.com>:> I usually just use Rack::Static: > > module App > ?use Rack::Static, :urls => [''/static''] > end > > This would serve ./static/jquery.js at > localhost:3301/static/jquery.js, though - with the directory included > in URL - but will also serve files from subdirectories recursively (I > don''t know if Rack::File does this).Yeah, that works, but I hate how /static/ is needed in the URL. The only reason Before is actually needed is because no-one in Rack thought of creating a Rack::File-ish middleware. Rack::Cascade works nice, but it can''t be used as a middleware. This simply turns Rack::Cascade into a middleware.