Commit addd09f04e054ce650c75245d5650ac2cfd79eaf
Committed by
Rodrigo Souto
1 parent
f04df39e
Exists in
master
and in
21 other branches
API: adding support for ajax calls
Showing
3 changed files
with
13 additions
and
0 deletions
Show diff stats
Gemfile
| ... | ... | @@ -22,6 +22,9 @@ gem 'eita-jrails', '>= 0.9.5', :require => 'jrails' |
| 22 | 22 | gem 'grape', '~> 0.8.0' |
| 23 | 23 | gem 'grape-entity' |
| 24 | 24 | gem 'grape-swagger' |
| 25 | +gem 'rack-cors' | |
| 26 | +gem 'rack-contrib' | |
| 27 | + | |
| 25 | 28 | #gem 'grape-swagger-rails' |
| 26 | 29 | |
| 27 | 30 | # FIXME list here all actual dependencies (i.e. the ones in debian/control), | ... | ... |
config/application.rb
| ... | ... | @@ -133,5 +133,12 @@ module Noosfero |
| 133 | 133 | |
| 134 | 134 | Noosfero::Plugin.setup(config) |
| 135 | 135 | |
| 136 | + config.middleware.use Rack::Cors do | |
| 137 | + allow do | |
| 138 | + origins '*' | |
| 139 | + resource 'api/*', :headers => :any, :methods => [:get, :post] | |
| 140 | + end | |
| 141 | + end | |
| 142 | + | |
| 136 | 143 | end |
| 137 | 144 | end | ... | ... |
lib/noosfero/api/api.rb
| 1 | 1 | require 'grape' |
| 2 | +#require 'rack/contrib' | |
| 2 | 3 | Dir["#{Rails.root}/lib/noosfero/api/*.rb"].each {|file| require file} |
| 3 | 4 | module Noosfero |
| 4 | 5 | module API |
| 5 | 6 | class API < Grape::API |
| 7 | + use Rack::JSONP | |
| 8 | + | |
| 6 | 9 | before { start_log } |
| 7 | 10 | before { setup_multitenancy } |
| 8 | 11 | before { detect_stuff_by_domain } | ... | ... |