Created
April 24, 2014 14:02
-
-
Save tiagogeraldi/11255684 to your computer and use it in GitHub Desktop.
cross access config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra/cross_origin' | |
class TweekRecommender < Sinatra::Base | |
include SinatraSimpleRouter | |
configure do | |
enable :cross_origin | |
set :allow_origin, :any | |
set :allow_methods, [:get, :post, :options] | |
set :allow_credentials, true | |
set :max_age, "1728000" | |
set :expose_headers, ['Content-Type'] | |
end | |
rescue_exception MongoMapper::DocumentNotFound do |exception, controller| | |
controller.render json: {error: exception.document.errors}, status: 404 | |
end | |
rescue_exception MongoMapper::DocumentNotValid do |exception, controller| | |
controller.render json: {error: exception.document.errors}, status: 409 | |
end | |
rescue_exception Parameter::NotFound do |exception, controller| | |
controller.render json: {error: "'#{exception.object}' parameter is required"}, status: 400 | |
end | |
version :v2 do | |
match :post , '/events/watch', EventsController, :watch | |
match :post , '/events/share', EventsController, :share | |
match :post , '/events/favorite', EventsController, :favorite | |
match :post , '/events/view', EventsController, :view | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment