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?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With