Created
September 9, 2014 11:17
-
-
Save eiriklv/74b1b544ff255f0f9ba4 to your computer and use it in GitHub Desktop.
Express allow CORS
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
module.exports.allowCORS = function(app) { | |
var allowCrossDomain = function(req, res, next) { | |
res.header('Access-Control-Allow-Origin', '*'); | |
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'); | |
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization'); | |
if ('OPTIONS' == req.method) { | |
res.send(200); | |
} else { | |
next(); | |
} | |
}; | |
app.use(allowCrossDomain); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment