If you also want to protect images, stylesheets and javascripts behind basic auth, you need to install Rack :: Auth :: Basic first:
use Rack::Auth::Basic, "Restricted Area" do |username, password| [username, password] == ['admin', 'admin'] end use Rack::Static, :urls => ["/stylesheets", "/images", "/javascripts"], :root => "public" run lambda { |env| [ 200, { 'Content-Type' => 'text/html', 'Cache-Control' => 'public, max-age=86400' }, File.open('public/index.html', File::RDONLY) ] }
Titas
source share