[enh] Allow CORS on every route. Add comments.

This commit is contained in:
opi 2016-04-26 09:24:33 +02:00
parent 98738741e2
commit f1e8f2a108

View file

@ -49,7 +49,9 @@ not_found do
halt 404, { :error => "Not found" }.to_json
end
# Common tasks and settings for every route
before do
# Ban IP on flood
if Ipban.first(:ip_addr => request.ip)
halt 410, "Your ip is banned from the service"
end
@ -64,7 +66,12 @@ before do
Iplog.create(:ip_addr => request.ip, :visited_at => Time.now)
end
end
# Always return json
content_type :json
# Allow CORS
headers['Access-Control-Allow-Origin'] = '*'
end
# Check params
@ -97,12 +104,10 @@ get '/' do
end
get '/domains' do
headers['Access-Control-Allow-Origin'] = '*'
DOMAINS.to_json
end
get '/test/:subdomain' do
headers['Access-Control-Allow-Origin'] = '*'
if entry = Entry.first(:subdomain => params[:subdomain])
halt 409, { :error => "Subdomain already taken: #{entry.subdomain}" }.to_json
else