-
-
Save hikmahgumelar/704ef7df5c1dff6ebf7f to your computer and use it in GitHub Desktop.
Enabling CORS in Angular JS with NodeJS/Express
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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