Allow CORS REST request to a Express/Node.js application on Heroku -


i've written rest api on express framework node.js works requests js console in chrome, , url bar, etc. i'm trying working requests app, on different domain (cors).

the first request, made automatically javascript front end, /api/search?uri=, , appears failing on "preflight" options request.

in express app, adding cors headers, using:

var allowcrossdomain = function(req, res, next) {     res.header('access-control-allow-origin', '*');     res.header('access-control-allow-methods', 'get,put,post,delete,options');     res.header('access-control-allow-headers', 'content-type, authorization, content-length, x-requested-with');      // intercept options method     if ('options' == req.method) {       res.send(200);     }     else {       next();     } }; 

and:

app.configure(function () {   app.use(express.bodyparser());   app.use(express.methodoverride());   app.use(app.router);   app.use(allowcrossdomain);   app.use(express.static(path.join(application_root, "public")));   app.use(express.errorhandler({ dumpexceptions: true, showstack: true })); }); 

from chrome console these headers:

request url:http://furious-night-5419.herokuapp.com/api/search?uri=http%3a%2f%2flocalhost%3a5000%2fcollections%2f1%2fdocuments%2f1

request method:options

status code:200 ok

request headers

accept:*/* accept-charset:iso-8859-1,utf-8;q=0.7,*;q=0.3 accept-encoding:gzip,deflate,sdch accept-language:en-us,en;q=0.8 access-control-request-headers:origin, x-annotator-auth-token, accept access-control-request-method:get connection:keep-alive host:furious-night-5419.herokuapp.com origin:http://localhost:5000 referer:http://localhost:5000/collections/1/documents/1 user-agent:mozilla/5.0 (macintosh; intel mac os x 10_7_4) applewebkit/536.5 (khtml, gecko) chrome/19.0.1084.56 safari/536.5 

query string parameters

uri:http://localhost:5000/collections/1/documents/1 

response headers

allow:get connection:keep-alive content-length:3 content-type:text/html; charset=utf-8 x-powered-by:express 

does lack of proper headers being sent api application?

thanks.

i've cheked code on clean expressjs app , works fine.

try move app.use(allowcrossdomain) top of configure function.


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -