Skip to content

Instantly share code, notes, and snippets.

@mikeerickson
Forked from dirkk0/gist:5967221
Last active December 25, 2015 00:29
Show Gist options
  • Save mikeerickson/6888058 to your computer and use it in GitHub Desktop.
Save mikeerickson/6888058 to your computer and use it in GitHub Desktop.
Allowing CORS with AngularJS and Node/Express
// in AngularJS (client)
myApp.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
}]);
// in Express/nodeJS
// in NodeJS/Express (server)
app.all('/*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Methods", "GET, POST","PUT");
next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment