Skip to content

Instantly share code, notes, and snippets.

@amitkhare
Last active January 15, 2018 12:50
Show Gist options
  • Save amitkhare/f6ab226113669a8f3b5e1996bf20b8d8 to your computer and use it in GitHub Desktop.
Save amitkhare/f6ab226113669a8f3b5e1996bf20b8d8 to your computer and use it in GitHub Desktop.
// CORS middleware
app.use((req, res, next)=>{
res.header('Access-Control-Allow-Origin','*')
res.header('Access-Control-Allow-Credentials','true')
res.header('Access-Control-Allow-Headers','X-Requested-With, Origin, Content-Type, X-Auth-Token , Authorization')
if(req.method === "OPTIONS"){
res.header('Access-Control-Allow-Methods','GET, PUT, POST, PATCH, DELETE, OPTIONS')
return res.status(200).json({});
}
next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment