Created
September 11, 2014 18:49
-
-
Save m-philipp/07b396ab13b0d8535dc5 to your computer and use it in GitHub Desktop.
Adding CORS to express
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
| function allowCrossDomain(req, res, next) { | |
| res.header('Access-Control-Allow-Origin', '*'); | |
| res.header('Access-Control-Allow-Headers', 'x-requested-with, Content-Type, Auth-Token'); | |
| // intercept OPTIONS method | |
| if ('OPTIONS' == req.method) { | |
| res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'); | |
| res.send(204); | |
| } | |
| else { | |
| if (req.header('x-requested-with')) { | |
| res.header('x-requested-with', req.header('x-requested-with')); | |
| } | |
| next(); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment