-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
36 lines (28 loc) · 938 Bytes
/
app.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
require 'sinatra'
require 'sinatra/cross_origin'
# cross origin setup
register Sinatra::CrossOrigin
set :allow_origin, ['http://localhost/', 'http://127.0.0.1', 'http://myapp.com']
set :allow_methods, [:get, :post, :options]
get '/' do
'This is a logger bridge app. GET /log for details.'
end
get '/log' do
cross_origin
'This app accepts GET (with query params) or POST requests to /log from client-side apps. Try it!'
end
options '/log' do
cross_origin
# Works around a bug in OPTIONS handling with sinatra/cross-origin
# Alternative: https://github.com/britg/sinatra-cross_origin/issues/18#issuecomment-115380221
response.headers["Allow"] = "HEAD, GET, PUT, POST, DELETE, OPTIONS"
response.headers["Access-Control-Allow-Headers"] = "X-Requested-With, X-HTTP-Method-Override, Content-Type, Cache-Control, Accept"
200
end
post '/log' do
cross_origin
request.params.each do |param|
logger.info(param)
end
204
end