48 lines
1.1 KiB
Ruby
48 lines
1.1 KiB
Ruby
require 'sinatra'
|
|
require 'sinatra/activerecord'
|
|
require './config'
|
|
require 'json'
|
|
require 'sinatra/cookies'
|
|
require 'elasticsearch'
|
|
require 'xxhash'
|
|
require 'pony'
|
|
|
|
|
|
Dir[File.dirname(__FILE__) + '/models/*.rb'].each {|file| require file }
|
|
|
|
set :bind, '0.0.0.0'
|
|
|
|
|
|
before do
|
|
content_type :json
|
|
# TODO: before running to production change this so that only specific
|
|
# domain is allowed
|
|
|
|
headers 'Access-Control-Allow-Origin' => 'http://localhost:3001',
|
|
'Access-Control-Allow-Methods' => ['OPTIONS', 'GET', 'POST','PUT'].join(','),
|
|
'Access-Control-Allow-Headers' => 'Origin, X-Requested-With, Content-Type, Accept',
|
|
'Access-Control-Expose-Headers' => 'X-Total-Count',
|
|
'Access-Control-Allow-Credentials' => 'true'
|
|
|
|
request.body.rewind
|
|
json_string = request.body.read
|
|
@json_params = JSON.parse json_string if json_string.length > 1
|
|
|
|
if request.request_method == 'OPTIONS'
|
|
halt 200
|
|
end
|
|
end
|
|
|
|
|
|
helpers Sinatra::Cookies
|
|
|
|
def xxhash(text)
|
|
seed = 31337
|
|
XXhash.xxh32(text, seed)
|
|
end
|
|
|
|
|
|
|
|
|
|
Dir[File.dirname(__FILE__) + '/controllers/*.rb'].each {|file| require file }
|