-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.rb
83 lines (71 loc) · 1.98 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
require 'roda'
require 'erubi'
require './models'
class App < Roda
plugin :render, :escape => %w|erb erubi|
plugin :partials
plugin :public
plugin :content_for
plugin :multi_route
plugin :type_routing, :types => {
:csv => 'text/csv',
:jsonld => 'application/ld+json',
:geojson => 'application/geo+json'
}
plugin :not_found do
view("error_page")
end
plugin :error_handler do |e|
case e
when Sequel::NoMatchingRow
if e.dataset
@page_title = "#{e.dataset.model} Not Found"
else
@page_title = "Database Entry Not Found"
end
response.status = 404
view("error_page")
else
next super(e) if ENV['RACK_ENV'] == 'development'
@page_title = "Internal Server Error"
response.status = 500
view("error_page")
end
end
if ENV['RACK_ENV'] == 'production'
plugin :default_headers,
'Cache-Control' => 'public,max-age=3600',
'Strict-Transport-Security' => 'max-age=16070400; includeSubDomains',
'X-Frame-Options' => 'deny'
end
Dir["routes/*.rb"].each {|file| require_relative file }
route do |r|
r.public
r.multi_route
r.root do
# 70 logos is enough for 23 * 3 rows
@logos = Logo.where(:size => '128x128')
.order(Sequel.lit('RANDOM()'))
.limit(70)
.eager_graph(:service => :default_bearer).all
view('homepage')
end
r.get 'logos' do
view('logos')
end
r.get 'sitemap' do
models = [Authority, Multiplex, Service, Transmitter]
@paths = ['/', '/logos']
@paths += models.map {|m| "/#{m.table_name}"}
@paths += models.map {|m| m.all.map {|a| a.path} }.flatten
@paths += County.all.map {|c| "/transmitters/counties/#{c.url_key}" }
@paths += ['/transmitters/all']
r.xml { render('sitemap') }
end
r.get 'gems' do
@specs = Gem::loaded_specs.values.sort_by(&:name)
view('gems')
end
end
require './helpers'
end