-
Notifications
You must be signed in to change notification settings - Fork 10
/
healer.rb
52 lines (43 loc) · 1.23 KB
/
healer.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
require 'sinatra'
require 'sinatra/cross_origin'
require 'sinatra/namespace'
require 'sinatra/json'
require 'ipaddr'
require 'pagerduty'
require 'rest-client'
require_relative 'app_config'
class Healer < Sinatra::Base
API_VERSION = '1'
API_PREFIX = 'healer'
API_URL = "/#{API_PREFIX}/v#{API_VERSION}"
$healer = RestClient::Resource.new(
"https://#{AppConfig::NETHEALER.server}/healer/v1/",
headers: { content_type: 'application/json' },
verify_ssl: false
)
$debug = 2
register Sinatra::CrossOrigin
register Sinatra::Namespace
set :allow_origin, :any
set :allow_methods, [:get, :post, :options]
set :allow_credentials, true
set :max_age, '1728000'
set :expose_headers, ['Content-Type']
Rack::Utils.key_space_limit = 262144
configure do
enable :cross_origin
end
before do
if request.request_method == 'OPTIONS'
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'POST'
halt 200
end
end
end
def require_directory(directory)
Dir[File.join(File.dirname(__FILE__), directory, '**')].each do |route|
require route
end
end
%w[jobs lib routes models serializers actions-enabled].each { |dir| require_directory dir }