-
Notifications
You must be signed in to change notification settings - Fork 1
/
fp_sin.rb
66 lines (53 loc) · 1.94 KB
/
fp_sin.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
# fp-sin 0.2.0
# By: Josh Ellithorpe 2011-2015
# Simple Sinatra shell with all the goodies.
# thin -R config.ru start
# http://localhost:3000/
# Shut up errors
$VERBOSE = nil
# Raise an error if we don't have a compatible ruby version.
raise LoadError, 'Ruby 1.9.2 required' if RUBY_VERSION < '1.9.2'
# Add lib directory to load path
$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
require "dependencies"
# Main application class.
class FpSinApp < Sinatra::Base
set :root, File.dirname(__FILE__)
set :locales, File.join(File.dirname(__FILE__), 'config', 'en.yml')
set :memcached, '127.0.0.1:11211'
set :caching, true
set :cache_timeout, 120
set :database_file, File.join('config', 'database.yml')
set :cache, settings.caching ? Dalli::Client.new(settings.memcached, {:namespace => 'fps_', :expires_in => settings.cache_timeout}) : CacheProxy.new()
use Rack::FiberPool, :size => 100 unless test?
use Rack::Session::Cookie, :key => 'rack.session',
#:domain => 'foo.com',
:path => '/',
:expire_after => 2592000,
:secret => ENV['SESSION_SECRET'] || 'DEFAULT_SESSION_KEY',
:old_secret => ENV['OLD_SESSION_SECRET'] || 'DEFAULT_OLD_SESSION_KEY'
register Sinatra::I18n
register Sinatra::ActiveRecordExtension
register Sinatra::Flash
register Sinatra::SinatraAuthentication
set :sinatra_authentication_view_path, "#{File.join(Pathname(__FILE__).dirname.expand_path, "views", "auth")}"
helpers ApplicationHelper
get '/' do
haml :index
end
get '/main.css' do
cache_control :public, :must_revalidate, :max_age => (settings.cache_timeout * 10)
set_content_type(:css)
scss :main
end
# Page not found handler
not_found do
flash.now[:error] = t('http_not_found')
haml :index
end
# Error handler
error do
flash.now[:error] = t('http_error')
haml :index
end
end