forked from slack-ruby/slack-ruby-bot-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware.rb
45 lines (38 loc) · 1.13 KB
/
middleware.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
require 'rack/cors'
require 'rack-rewrite'
require 'rack-server-pages'
require 'otr-activerecord' if SlackRubyBotServer::Config.activerecord? && !defined?(::Rails)
module SlackRubyBotServer
module Api
class Middleware
def self.logger
@logger ||= begin
STDOUT.sync = true
Logger.new(STDOUT)
end
end
def self.instance
@instance ||= Rack::Builder.new do
use OTR::ActiveRecord::ConnectionManagement if SlackRubyBotServer::Config.activerecord? && defined?(::OTR)
use Rack::Cors do
allow do
origins '*'
resource '*', headers: :any, methods: %i[get post]
end
end
# rewrite HAL links to make them clickable in a browser
use Rack::Rewrite do
r302 %r{(\/[\w\/]*\/)(%7B|\{)?(.*)(%7D|\})}, '$1'
end
use Rack::ServerPages do |config|
config.view_path = SlackRubyBotServer::Config.view_paths
end
run Middleware.new
end.to_app
end
def call(env)
Endpoints::RootEndpoint.call(env)
end
end
end
end