-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathapp.rb
59 lines (51 loc) · 1.37 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
require 'sinatra'
require 'sinatra/json'
require 'dotenv'
require 'newrelic_rpm'
require 'github_repos'
require 'dalli'
require 'rack-cache'
require 'pry'
Dotenv.load
class App < Sinatra::Base
if ENV["MEMCACHEDCLOUD_SERVERS"]
cache = Dalli::Client.new(ENV["MEMCACHEDCLOUD_SERVERS"].split(","),
{:username => ENV["MEMCACHEDCLOUD_USERNAME"],
:password => ENV["MEMCACHEDCLOUD_PASSWORD"],
:failover => true,
:socket_timeout => 1.5,
:socket_failure_delay => 0.2
})
use Rack::Cache,
verbose: true,
metastore: cache,
entitystore: cache
end
configure do
set :show_exceptions, false
end
get '/' do
cache_control :public, max_age: 3600 # 60 mins.
erb :home
end
get '/:username/:repo' do
cache_control :public, max_age: 1800 # 30 mins.
begin
@repo = "#{params[:username]}/#{params[:repo]}"
original = GithubRepos.new(@repo).original
forks = GithubRepos.new(original.full_name).popular_forks
# binding.pry
# puts "fork", original
erb :forks, locals: { original: original, forks: forks }
rescue Octokit::NotFound
erb :err400
end
end
not_found do
@repo = request.path
erb :err400
end
error do
erb :err500
end
end