This repository has been archived by the owner on Jun 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.ru
executable file
·72 lines (58 loc) · 1.44 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Common includes
Dir[File.dirname(__FILE__) + '/lib/includes.rb'].each {|file| require file }
# Commands
Dir[File.dirname(__FILE__) + '/cmd/*.rb'].each {|file| require file }
# Main app file
Dir[File.dirname(__FILE__) + '/app.rb'].each {|file| require file }
# set up log levels
configure :test do
set :logging, Logger::ERROR
end
configure :development do
set :logging, Logger::DEBUG
set(:cookie_options) do
{ :expires => Time.now + 3600 * 24 * 5 }
end
end
configure :production do
set :logging, Logger::INFO
set(:cookie_options) do
{ :expires => Time.now + 3600 * 24 * 5 }
end
end
# LaaS
map "/" do
run Sinatra::Application
end
# DB Browser
require "redis-browser"
map "/db" do
settings = {
"connections" => {
"default" => {
"url" => ENV["REDIS_URI"]
}
}
}
RedisBrowser.configure(settings)
RedisBrowser::Web.class_eval do
use Rack::Auth::Basic, "Protected Area" do |username, password|
username == ENV["REDIS_UI_USER"] && password == ENV["REDIS_UI_PASS"]
end
end
run RedisBrowser::Web
end
# Cleanup task
require 'logger'
logger = Logger.new(STDOUT)
# Catch SIGTERM and let app kill itself
# Because otherwise, when Heroku kills the app, we get FATAL errors
Signal.trap('TERM') do
current_pid = Process.pid
signal = "SIGINT"
Process.kill(signal, current_pid)
end
at_exit do
# Placeholder for any cleanup code needed when app shuts down
logger.info("Cleanup") {"Bye"}
end