Files
old-ribica/front-api/app.rb

63 lines
1.5 KiB
Ruby
Raw Normal View History

2015-01-22 06:38:48 +01:00
require 'sinatra'
require 'sinatra/activerecord'
require './config'
2015-09-26 11:58:01 +02:00
require './helpers'
2015-01-22 06:38:48 +01:00
require 'json'
require 'sinatra/cookies'
require 'elasticsearch'
require 'xxhash'
2015-09-26 11:58:01 +02:00
require 'trello'
2015-09-21 06:31:52 +02:00
require 'sendgrid-ruby'
2015-01-22 06:38:48 +01:00
2015-09-26 11:58:01 +02:00
Trello.configure do |config|
# API key generated by visiting https://trello.com/1/appKey/generate
2015-10-31 08:24:44 +01:00
config.developer_public_key = RibicaConfig::TRELLO_DEVELOPER_PUBLIC_KEY
2015-09-26 11:58:01 +02:00
# Member token
# larry-price.com/blog/2014/03/18/connecting-to-the-trello-api/
2015-10-31 08:24:44 +01:00
config.member_token = RibicaConfig::TRELLO_MEMBER_TOKEN
2015-09-26 11:58:01 +02:00
end
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-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-07-05 13:24:09 +02:00
2015-06-21 15:01:49 +02:00
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'
unless Helper::do_not_parse_as_json.include? env['PATH_INFO']
request.body.rewind
2016-01-07 13:28:57 +01:00
json_string = request.body.read
@json_params = JSON.parse json_string if json_string.length > 1
end
if request.request_method == 'OPTIONS'
halt 200
end
2015-01-22 06:38:48 +01:00
end
helpers Sinatra::Cookies
def xxhash(text)
seed = 31337
XXhash.xxh32(text, seed)
end
2015-02-26 06:48:34 +01:00
2015-01-22 06:38:48 +01:00
Dir[File.dirname(__FILE__) + '/controllers/*.rb'].each {|file| require file }