Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sinatra - Multiple public directories

I'd like to link to a CSS and JavaScript files outside of the default public directory that Sinatra sets up.

I know I can use set :public to change the directory, but I want to retain the default directory along with the other 'public_2'.

Is there a way to do this?

like image 916
ash Avatar asked Sep 23 '13 18:09

ash


1 Answers

You could use the TryStatic middleware from rack-contrib:

require 'rack/contrib/try_static'

use Rack::TryStatic, :root => 'public_2', :urls => %w[/]

Now the public and public_2 directories will both be searched for files that match the request (public_2 will be searched first, since the TryStatic middleware will be hit before the app itself).

like image 137
matt Avatar answered Oct 11 '22 18:10

matt