-
Notifications
You must be signed in to change notification settings - Fork 9
/
config.ru
81 lines (67 loc) · 1.9 KB
/
config.ru
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
# frozen_string_literal: true
require_relative "config/bootstrap"
if ENV["SENTRY_DSN"]
require "sentry-ruby"
Sentry.init do |config|
# Raven reports on the following environments
config.enabled_environments = %w[development staging production]
end
use Sentry::Rack::CaptureExceptions
end
if ENV["ROLLBAR_ACCESS_TOKEN"]
require "rollbar/middleware/rack"
Rollbar.configure do |config|
config.access_token = ENV["ROLLBAR_ACCESS_TOKEN"]
config.environment = ENV["RACK_ENV"]
end
use Rollbar::Middleware::Rack
end
if ENV["RACK_ENV"] == "production"
unless ENV["DISABLE_SSL_FORCE"]
require "rack/ssl-enforcer"
use Rack::SslEnforcer, except: ["/health", "/setup"]
end
# Log all requests in apache log file format
use Rack::CommonLogger
end
# check env vars
Box.configuration.valid?
# Load database connection validator middleware
require_relative "box/middleware/connection_validator"
use Box::Middleware::ConnectionValidator, DB
# Load authentication middleware
use Box.configuration.auth_provider
# Enable CORS to enable access to our API from frontend apps and our swagger documentation
require "rack/cors"
use Rack::Cors do
allow do
origins "*"
resource "*", headers: :any, methods: [:get, :post, :put, :delete, :options]
end
end
# Deliver assets
use Rack::Static, urls: [
"/swagger-ui-standalone-preset.js",
"/swagger-ui-bundle.js",
"/swagger-ui-standalone-preset.js",
"/swagger-ui.css",
"/swagger-ui.js",
"/doc/swagger-v1.json",
"/doc/swagger-v2.json"
], root: "public/swagger"
# Deliver html/json documentation template
map "/docs" do
run lambda { |env|
[
200,
{
"Content-Type" => "text/html",
"Cache-Control" => "public, max-age=86400"
},
File.open("public/swagger/index.html", File::RDONLY)
]
}
end
# Finally, load application and all its endpoints
require_relative "box/apis/base"
run Box::Apis::Base