Last active
August 9, 2017 12:26
-
-
Save ehansen31/20ac5663551678f12b8afd7dc22fc6bd to your computer and use it in GitHub Desktop.
Snippet that should be placed after app.use(express) that should allow cors from any domain
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
app.use(function(req, res, next) { | |
res.header('Access-Control-Allow-Credentials', true); | |
res.header('Access-Control-Allow-Origin', req.headers.origin); | |
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'); | |
res.header('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept'); | |
if ('OPTIONS' == req.method) { | |
res.send(200); | |
} else { | |
next(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment