Last active
January 15, 2018 12:50
-
-
Save amitkhare/f6ab226113669a8f3b5e1996bf20b8d8 to your computer and use it in GitHub Desktop.
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((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