Skip to content

Instantly share code, notes, and snippets.

@tshaddix
Last active December 21, 2015 00:58
Show Gist options
  • Save tshaddix/6223907 to your computer and use it in GitHub Desktop.
Save tshaddix/6223907 to your computer and use it in GitHub Desktop.
Allowing CORS with ExpressJS and AngularJS
// Add COR ability
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
$httpProvider.defaults.withCredentials = true;
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