HTTP basic auth for Rack::Static app on Heroku HTTP basic auth for Rack::Static app on Heroku heroku heroku

HTTP basic auth for Rack::Static app on Heroku


use Rack::Static,   :urls => ["/stylesheets", "/images", "/javascripts"],  :root => "public"#SOLUTION:use Rack::Auth::Basic, "Restricted Area" do |username, password|  [username, password] == ['admin', 'admin']endrun lambda { |env|  [    200,     {      'Content-Type'  => 'text/html',       'Cache-Control' => 'public, max-age=86400'     },    File.open('public/index.html', File::RDONLY)  ]}


If you want to also protect images, stylesheets and javascripts behind basic auth, you need to put Rack::Auth::Basic first:

use Rack::Auth::Basic, "Restricted Area" do |username, password|  [username, password] == ['admin', 'admin']enduse 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)  ]}