CORS issue with Rails 3 consuming mongodb rest api -


i'm experiencing cross-origin resource sharing (cors) issue rails 3 application consuming mongodb simple rest api. have coffeescript/javascript trying consume mongodb simple rest api, chrome prevents following console message:

 xmlhttprequest cannot load http://127.0.0.1:28017/my-db/my-collection/. origin http://127.0.0.1:3000 not allowed access-control-allow-origin. 

i've added 2 controller methods blog post:

before_filter :cors_preflight_check after_filter :cors_set_access_control_headers  def cors_set_access_control_headers   headers['access-control-allow-origin']  = '*'   headers['access-control-allow-methods'] = 'post, get, options'   headers['access-control-max-age']       = '1728000' end  def cors_preflight_check   if request.method == :options     headers['access-control-allow-origin']  = '*'     headers['access-control-allow-methods'] = 'post, get, options'     headers['access-control-allow-headers'] = 'content-type, x-requested-with, x-prototype-version'     headers['access-control-max-age']       = '1728000'     render text: '', content_type: 'text/plain'   end end 

i can see headers present rails page. however, still isn't working.

my best guess whatever web server mongodb simple rest api uses needs include headers, not rails app. can confirm or deny this?

i read somewhere use proxy re-write rule in nginx. however, tedious, since i'm not running nginx development, on production server.

whatever headers setting in rails have nothing headers sent chrome ajax request mongodb directly. need use jsonp around cors issues.

start mongod --rest , --jsonp , mongod setup appropriately. make jsonp request using jquery or whatever , should work fine.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -