/
config.ru
40 lines (35 loc) · 1.03 KB
/
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
35
36
37
38
39
40
require 'json'
require 'active_support/core_ext/string'
require 'handlebars_assets'
class QuanApp
def call(env)
if env['REQUEST_PATH'] =~ /\.json/
[200, {}, [File.open('json/'+env['REQUEST_PATH']).read]]
else
[200, {}, [File.open('assets/html/app.html').read]]
end
end
end
app = Rack::Builder.app do
use Rack::Head
map('/') do
quan_app = QuanApp.new
protected_quan_app = Rack::Auth::Basic.new(quan_app) do |username, password|
ENV['RACK_APP_KEY'] == username && ENV['RACK_APP_SECRET'] == password
end
protected_quan_app.realm = 'QuanApp Hight Profit'
pretty_protected_quan_app = Rack::ShowStatus.new(Rack::ShowExceptions.new(protected_quan_app))
run pretty_protected_quan_app
end
map '/assets' do
use Rack::Deflater
env = Sprockets::Environment.new
env.append_path 'assets/javascripts'
env.append_path 'assets/stylesheets'
env.append_path 'assets/templates'
env.append_path 'assets/images'
env.append_path HandlebarsAssets.path
run env
end
end
run app