Ruby Heroku上Rack::Static应用程序的HTTP基本身份验证
我在Heroku上有一个简单的Rack应用程序。config.ru:Ruby Heroku上Rack::Static应用程序的HTTP基本身份验证,ruby,heroku,rack,basic-authentication,Ruby,Heroku,Rack,Basic Authentication,我在Heroku上有一个简单的Rack应用程序。config.ru: use Rack::Static, :urls => ["/stylesheets", "/images", "/javascripts"], :root => "public" run lambda { |env| [ 200, { 'Content-Type' => 'text/html', 'Cache-Control' => 'pub
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)
]
}
如何将HTTP基本身份验证添加到此文件?仅在生产环境中工作的奖励点数
谢谢如果您还想在basic auth后面保护图像、样式表和Java脚本,您需要首先放置Rack::auth::basic:
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)
]
}
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)
]
}