Skip to content

Instantly share code, notes, and snippets.

@zprima
Last active January 27, 2019 11:23
Show Gist options
  • Save zprima/3a669188333b904660de9d28c6a3cf1c to your computer and use it in GitHub Desktop.
Save zprima/3a669188333b904660de9d28c6a3cf1c to your computer and use it in GitHub Desktop.
medium_p1_c2
//...
// 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