Skip to content

Instantly share code, notes, and snippets.

@nsourov
Created January 8, 2018 08:42
Show Gist options
  • Save nsourov/7bd0bd2557536341d0282e4f1eb7b67c to your computer and use it in GitHub Desktop.
Save nsourov/7bd0bd2557536341d0282e4f1eb7b67c to your computer and use it in GitHub Desktop.
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*"); // "*" for public access and www.example.com for specific uses
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
);
if (req.method === 'OPTIONS') {
res.header('Access-Control-Allow-Methods', 'PUT, POST, PATCH, DELETE, GET');
return res.status(200).json({});
}
next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment