Skip to content

Instantly share code, notes, and snippets.

@inodaf
Last active March 25, 2019 16:32
Show Gist options
  • Save inodaf/4f2581fac0e1c8484bbec86e66cffbf7 to your computer and use it in GitHub Desktop.
Save inodaf/4f2581fac0e1c8484bbec86e66cffbf7 to your computer and use it in GitHub Desktop.
Falando em Falhas: 2K to rule the life.
// Setting dynamic CORS for non-options Request
app.use(cors((req, cb) => {
const companyDNS = '.mycompany.xyz'
const isTrusted = req.header('Origin').indexOf(companyDNS) >= 1
// Some more business logics...
return cb(null, {
credentials: true,
origin: isTrusted
})
}))
// Setting Default CORS for Option Requests
app.options('*', cors({ credentials: true, origin: true }))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment