-
Notifications
You must be signed in to change notification settings - Fork 24
/
server.rb
42 lines (35 loc) · 852 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'
require 'erb'
use Rack::Logger
set :config_path, File.expand_path('../config.yml', __FILE__)
set :config, ->{ YAML.load(ERB.new(File.read(config_path)).result) }
helpers do
def logger
request.logger
end
def config
settings.config[params['app']] || {}
end
end
get '/' do
status 200
"ok"
end
post '/' do
logger.info "RECIEVED POST: #{params.inspect}"
forwardable_params = params.dup
forwardable_params.delete('splat')
forwardable_params.delete('captures')
config.values.each do |url|
uri = URI.parse(url)
query = Rack::Utils.parse_query(uri.query)
query = forwardable_params.merge(query)
logger.info "POSTING TO: #{uri}, BODY: #{Rack::Utils.build_query(query)}"
HTTParty.post( uri.to_s, body: query )
end
status 201
"ok"
end