Skip to content

Instantly share code, notes, and snippets.

@Jobayer-Ahmed
Last active July 3, 2018 02:55
Show Gist options
  • Save Jobayer-Ahmed/e3d1fcc5826aeec1b67db97f1e5e987e to your computer and use it in GitHub Desktop.
Save Jobayer-Ahmed/e3d1fcc5826aeec1b67db97f1e5e987e 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