Created
January 28, 2013 02:04
-
-
Save realguess/4652304 to your computer and use it in GitHub Desktop.
CORS support example adapted from https://github.com/visionmedia/express/blob/master/examples/cors/index.js
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
/** | |
* 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