forked from vmware-archive/pivotal-life
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ru
34 lines (27 loc) · 738 Bytes
/
config.ru
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'dashing'
require 'dotenv'
Dotenv.load
USERNAME = ENV['AUTH_USERNAME'] || 'admin'
PASSWORD = ENV['AUTH_PASSWORD'] || 'admin'
configure do
set :auth_token, 'YOUR_AUTH_TOKEN'
set :default_dashboard, 'default'
helpers do
def protected!
return if authorized?
headers['WWW-Authenticate'] = 'Basic realm="Restricted Area"'
halt 401, "Not authorized\n"
end
def authorized?
@auth ||= Rack::Auth::Basic::Request.new(request.env)
@auth.provided? and
@auth.basic? and
@auth.credentials and
@auth.credentials == [USERNAME, PASSWORD]
end
end
end
map Sinatra::Application.assets_prefix do
run Sinatra::Application.sprockets
end
run Sinatra::Application