-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
55 lines (45 loc) · 1.25 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
require 'rubygems'
require 'bundler'
Bundler.require
$: << File.expand_path('../', __FILE__)
require 'dotenv'
Dotenv.load
require 'active_record'
require 'sinatra/base'
require 'sinatra/json'
require 'sinatra/router'
require 'sinatra/namespace'
require 'app/models'
require 'app/routes'
require 'app/services'
require 'app/helpers'
require 'app/exceptions'
require 'multi_json'
module News
class App < Sinatra::Base
configure do
database_url = ENV.fetch('DATABASE_URL')
::ActiveRecord::Base.establish_connection(database_url)
::ActiveRecord::ConnectionAdapters::ConnectionManagement
end
use Sinatra::Router do
def version(version, &block)
condition = lambda do |env|
accept_headers = Sinatra::Request.new(env).accept
api_accept_header = accept_headers.find do |header|
Services::ApiHeaderMatcher[accept_header: header.to_s, vendor: 'news-app']
end
Services::ApiVersionExtracter[api_accept_header.to_s] == version
end
with_conditions(condition, &block)
end
version 2 do
mount Routes::V2::Stories
mount Routes::V2::Users
end
mount Routes::V1::Stories
mount Routes::V1::Users
end
end
end
include News::Models