Last active
December 21, 2015 00:58
-
-
Save tshaddix/6223907 to your computer and use it in GitHub Desktop.
Allowing CORS with ExpressJS and AngularJS
This file contains hidden or 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
| // Add COR ability | |
| $httpProvider.defaults.useXDomain = true; | |
| delete $httpProvider.defaults.headers.common['X-Requested-With']; | |
| $httpProvider.defaults.withCredentials = true; |
This file contains hidden or 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
| app.all('/*', function(req, res, next) { | |
| res.header("Access-Control-Allow-Origin", "{GRUNT_SERVER}"); | |
| res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); | |
| res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE"); | |
| res.header("Access-Control-Allow-Credentials", "true"); | |
| next(); | |
| }); | |
| // Session config. | |
| app.use(express.session({ | |
| secret : config.get(cookieSecret), | |
| key : 'sid', | |
| cookie : { | |
| maxAge : null, | |
| httpOnly : false | |
| } | |
| })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment