forked from jaredatron/deploy-hook-forker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.rb
42 lines (34 loc) · 843 Bytes
/
server.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
require 'sinatra'
require 'yaml'
require 'uri'
require 'httparty'
use Rack::Logger
set :config_path, File.expand_path('../config.yml', __FILE__)
set :config, ->{ YAML.load_file(config_path) }
helpers do
def logger
request.logger
end
def config
settings.config[params['app']] || {}
end
end
get '/' do
status 200
body 'ok'
end
post '/' do
logger.info "Received POST: #{params.inspect}"
forwardable_params = params.dup
forwardable_params.delete('splat')
forwardable_params.delete('captures')
config.each do |service, url|
uri = URI.parse(url)
query = Rack::Utils.parse_query(uri.query)
query = forwardable_params.merge(query)
logger.info "Forwarding to #{service}: #{uri}, BODY: #{Rack::Utils.build_query(query)}"
HTTParty.post( uri.to_s, body: query )
end
status 201
body 'ok'
end