Skip to content

Instantly share code, notes, and snippets.

@alarner
Created February 24, 2017 23:22
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 alarner/ec4076aa2de1533e4393c9377d063bd5 to your computer and use it in GitHub Desktop.
Save alarner/ec4076aa2de1533e4393c9377d063bd5 to your computer and use it in GitHub Desktop.
Allow Cross Domain Express
module.exports = function(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', 'Content-Type, Authorization, Content-Length, X-Requested-With');
// intercept OPTIONS method
if ('OPTIONS' == req.method) {
res.send(200);
}
else {
next();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment