Last active
January 27, 2019 11:23
-
-
Save zprima/3a669188333b904660de9d28c6a3cf1c to your computer and use it in GitHub Desktop.
medium_p1_c2
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
//... | |
// CORS middleware | |
app.use(function (req, res, next) { | |
// Allow Origins | |
res.header("Access-Control-Allow-Origin", "*"); | |
// Allow Methods | |
res.header("Access-Control-Allow-Methods", "GET, POST, PATCH, PUT, DELETE, OPTIONS"); | |
// Allow Headers | |
res.header("Access-Control-Allow-Headers", "Origin, Accept, Content-Type, Authorization"); | |
// Handle preflight, it must return 200 | |
if (req.method === "OPTIONS") { | |
// Stop the middleware chain | |
return res.status(200).end(); | |
} | |
// Next middleware | |
next(); | |
}); | |
//... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment