Skip to content

Instantly share code, notes, and snippets.

@realguess
Created January 28, 2013 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save realguess/4652304 to your computer and use it in GitHub Desktop.
Save realguess/4652304 to your computer and use it in GitHub Desktop.
/**
* Add CORS support.
*/
app.all('*', function (req, res, next) {
if (!req.get('Origin')) {
return next();
}
// use "*" here to accept any origin
res.set('Access-Control-Allow-Origin', '*');
res.set('Access-Control-Allow-Methods', 'GET, POST');
res.set('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type');
// res.set('Access-Control-Allow-Max-Age', 3600);
if ('OPTIONS' == req.method) {
return res.send(200);
}
next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment