Skip to content

Instantly share code, notes, and snippets.

@berat
Created August 12, 2020 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berat/95bd3b0fd072c3b5287b51a74cf4092d to your computer and use it in GitHub Desktop.
Save berat/95bd3b0fd072c3b5287b51a74cf4092d to your computer and use it in GitHub Desktop.
app.use(cors())
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
res.header(
'Access-Control-Allow-Headers',
'origin,x-requested-with, Content-Type, Authorization'
)
// intercept OPTIONS method
if ('OPTIONS' == req.method) {
res.send(200)
} else {
next()
}
}
app.use(allowCrossDomain)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment