Skip to content

Instantly share code, notes, and snippets.

@cjlyth
Created November 19, 2013 20:43
Show Gist options
  • Save cjlyth/7552207 to your computer and use it in GitHub Desktop.
Save cjlyth/7552207 to your computer and use it in GitHub Desktop.
CORS support for express
api.all('*', function(req, res, next){
if (!req.get('Origin')) return next();
// use "*" here to accept any origin
res.set('Access-Control-Allow-Origin', 'http://localhost:3000');
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