I'm using sails.js on my server (0.10.1) with CORS enabled. On my client I use restangular (1.4.0).
For each request I make, the client sends it twice, once as an OPTION and once as GET/POST.
So far this is normal, but it seems the sails is not handling the OPTION request well, as it fires the request twice.
I tried adding:
RestangularProvider.setDefaultHttpFields({withCredentials: true});
RestangularProvider.setDefaultRequestParams('jsonp', {callback: 'JSON_CALLBACK'});
And I'm sure the client is only firing the request once.
I have no idea how to start debugging this, any help would be appreciated.
Please see this issue on Github. It has been patched and will be in an upcoming patch release of Sails. In the meantime, an easy workaround is to just put the following in your config/routes.js file:
"OPTIONS /*": function (req, res) {res.send(200);}
Update
This is fixed in v0.10.2, so you should no longer have to specify your own OPTIONS
route.