-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.rb
72 lines (53 loc) · 1.65 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
# frozen_string_literal: true
require 'bundler/setup'
require 'sinatra/base'
require 'redis'
require 'json'
REDIS ||= Redis.new(url: ENV['REDIS_URL'])
class Rubies < Sinatra::Base
configure do
set :logging, true
set :protection, except: [:json_csrf]
set :host_authorization, { permitted_hosts: [] }
end
configure :production do
set :raise_errors, false
set :show_exceptions, false
set :static_cache_control, [:public, :must_revalidate, { max_age: 30672000 }]
end
set :app_file, __FILE__
set :root, File.dirname(settings.app_file)
set :public_folder, File.join(settings.root, 'public')
get '/' do
@normal = REDIS.lrange('rubies:web:normal', 0, -1)
@security = REDIS.lrange('rubies:web:security', 0, -1)
@statuses_ex = REDIS.lrange('rubies:web:statuses_ex', 0, -1)
@branches_ex = REDIS.lrange('rubies:web:branches_ex', 0, -1)
@releases_ex = REDIS.lrange('rubies:web:releases_ex', 0, -1)
@last_update = REDIS.get('rubies:web:last_update')
erb :index
end
get '/ping' do
halt :ok
end
before '/api/*' do
content_type :json
headers 'Access-Control-Allow-Methods' => 'HEAD, GET',
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Headers' => 'accept, authorization, origin'
end
get '/api/:key' do |key|
halt 404 unless REDIS.exists?("rubies:api:#{key}")
REDIS.get("rubies:api:#{key}")
end
not_found do
halt if request.path_info =~ %r{^/api/}
@title = 'Rubies | 404'
erb :not_found
end
error do
halt if request.path_info =~ %r{^/api/}
@title = 'Rubies | Error'
erb :error
end
end