-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.rb
107 lines (84 loc) · 2.8 KB
/
app.rb
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Initialize Sentry as soon as possible as recommended
if ENV['RACK_ENV'] == 'production'
require 'sentry-ruby'
Sentry.init do |config|
config.dsn = ENV['SENTRY_DSN']
config.traces_sample_rate = 0.01
if ENV['GIT_REV']
config.release = ENV['GIT_REV']
end
end
end
# Regular app startup begins now
require 'bundler/setup'
Bundler.require(:default)
require 'sinatra/redis'
require 'sinatra/cross_origin'
PumaWorkerKiller.enable_rolling_restart if ENV['RACK_ENV'] == 'production'
%w[models routes lib helpers].each do |d|
Dir["./#{d}/*.rb"].each { |file| require file }
end
class TreeStats < Sinatra::Base
configure :production do
use Sentry::Rack::CaptureExceptions
end
set :root, File.dirname(__FILE__)
set :sprockets, Sprockets::Environment.new(root)
set :precompile, [/\w+\.(?!js|css).+/, /application.(css|js)$/, /.+\.js/]
set :assets_prefix, '/assets'
set :digest_assets, true
set(:assets_path) { File.join public_folder, assets_prefix }
# Explicitly register Sinatra::Redis so the method `redis` is available
# to other parts of our application like routes
register Sinatra::Redis
# Routes (alpha order)
register Sinatra::TreeStats::Routing::Accounts
register Sinatra::TreeStats::Routing::Allegiances
register Sinatra::TreeStats::Routing::Chain
register Sinatra::TreeStats::Routing::General
register Sinatra::TreeStats::Routing::PlayerCounts
register Sinatra::TreeStats::Routing::Rankings
register Sinatra::TreeStats::Routing::Search
register Sinatra::TreeStats::Routing::Stats
register Sinatra::TreeStats::Routing::Titles
register Sinatra::TreeStats::Routing::Upload
register Sinatra::TreeStats::Routing::Dashboards
# CORS
register Sinatra::CrossOrigin
# Load server route last because it has catch-alls
register Sinatra::TreeStats::Routing::Server
configure do
# Turn on logging
enable :logging
# Mongoid
Mongoid.load!('./config/mongoid.yml')
Mongo::Logger.logger.level = ::Logger::INFO
# Redis
redis_url = ENV['REDIS_URL'] || 'redis://localhost:6379'
uri = URI.parse(redis_url)
set :redis, redis_url
# Resque
Resque.redis = Redis.new(host: uri.host, port: uri.port, password: uri.password)
# Setup Sprockets
sprockets.append_path File.join(root, 'assets', 'stylesheets')
sprockets.append_path File.join(root, 'assets', 'javascripts')
sprockets.append_path File.join(root, 'assets', 'images')
Sprockets::Helpers.configure do |config|
config.environment = sprockets
config.prefix = assets_prefix
config.digest = digest_assets
config.public_path = public_folder
end
# CORS
enable :cross_origin
end
helpers do
include Sprockets::Helpers
end
configure :production do
require 'newrelic_rpm'
end
not_found do
haml :not_found
end
end