2015-01-22 06:38:48 +01:00
|
|
|
require 'sinatra'
|
|
|
|
|
require 'sinatra/activerecord'
|
|
|
|
|
require './config'
|
|
|
|
|
require 'json'
|
2015-02-07 07:52:32 +01:00
|
|
|
require 'sinatra/cookies'
|
2015-03-21 00:00:36 +01:00
|
|
|
require 'elasticsearch'
|
2015-06-20 05:06:32 +02:00
|
|
|
require 'xxhash'
|
2015-03-21 00:00:36 +01:00
|
|
|
|
2015-01-22 06:38:48 +01:00
|
|
|
|
|
|
|
|
Dir[File.dirname(__FILE__) + '/models/*.rb'].each {|file| require file }
|
|
|
|
|
|
|
|
|
|
set :bind, '0.0.0.0'
|
|
|
|
|
|
2015-01-29 07:07:08 +01:00
|
|
|
|
2015-01-22 06:38:48 +01:00
|
|
|
before do
|
|
|
|
|
content_type :json
|
|
|
|
|
# TODO: before running to production change this so that only specific
|
|
|
|
|
# domain is allowed
|
2015-06-21 15:01:49 +02:00
|
|
|
headers 'Access-Control-Allow-Origin' => 'http://localhost:3001',
|
2015-02-08 08:29:24 +01:00
|
|
|
'Access-Control-Allow-Methods' => ['OPTIONS', 'GET', 'POST','PUT'],
|
|
|
|
|
'Access-Control-Allow-Headers' => 'Origin, X-Requested-With, Content-Type, Accept',
|
2015-02-15 14:21:50 +01:00
|
|
|
'Access-Control-Expose-Headers' => 'X-Total-Count',
|
2015-02-08 08:29:24 +01:00
|
|
|
'Access-Control-Allow-Credentials' => 'true'
|
|
|
|
|
|
2015-02-07 07:52:32 +01:00
|
|
|
request.body.rewind
|
2015-02-08 08:29:24 +01:00
|
|
|
json_string = request.body.read
|
2015-02-07 07:52:32 +01:00
|
|
|
@json_params = JSON.parse json_string if json_string.length > 1
|
2015-02-08 08:29:24 +01:00
|
|
|
|
|
|
|
|
if request.request_method == 'OPTIONS'
|
|
|
|
|
halt 200
|
|
|
|
|
end
|
2015-01-22 06:38:48 +01:00
|
|
|
end
|
|
|
|
|
|
2015-02-06 06:58:16 +01:00
|
|
|
|
2015-06-20 05:06:32 +02:00
|
|
|
helpers Sinatra::Cookies
|
2015-02-07 07:52:32 +01:00
|
|
|
|
2015-06-20 05:06:32 +02:00
|
|
|
def xxhash(text)
|
|
|
|
|
seed = 31337
|
|
|
|
|
XXhash.xxh32(text, seed)
|
|
|
|
|
end
|
2015-02-26 06:48:34 +01:00
|
|
|
|
|
|
|
|
|
2015-02-06 06:58:16 +01:00
|
|
|
|
2015-01-22 06:38:48 +01:00
|
|
|
|
|
|
|
|
Dir[File.dirname(__FILE__) + '/controllers/*.rb'].each {|file| require file }
|