I'm trying to implement http basic authentication in rails metal. Using this code:
class Api
def self.call(env)
if env["PATH_INFO"] =~ /^开发者_StackOverflow中文版\/client/
Rack::Auth::Basic.new(env) do |user, password|
raise 'ERROR'
end
But this block never executed? Any help will be appreciated!
Might I suggest this approach instead? In your config/environments/yourenv.rb just add
config.middleware.insert_after(::Rack::Lock, "::Rack::Auth::Basic", "Staging") do |u, p|
u == ENV['HTTPUSER'] && p == ENV['HTTPPASS']
end
精彩评论