Skip to content

Instantly share code, notes, and snippets.

@DWboutin
Created July 15, 2016 19:05
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 DWboutin/62b0ffe5cf24850a00a185c840370347 to your computer and use it in GitHub Desktop.
Save DWboutin/62b0ffe5cf24850a00a185c840370347 to your computer and use it in GitHub Desktop.
Express cross-origin options
export default function allowCrossOrigin(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
if ('OPTIONS' === req.method) {
res.sendStatus(200);
} else {
next();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment