Skip to content

Instantly share code, notes, and snippets.

@bekatom
Created April 12, 2016 05:28
Show Gist options
  • Save bekatom/0672e967ec734f64c9563eb64122f638 to your computer and use it in GitHub Desktop.
Save bekatom/0672e967ec734f64c9563eb64122f638 to your computer and use it in GitHub Desktop.
AllowCrossDomain Request , in multiple site only
function allowCrossDomain(req, res, next) {
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.header('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.header('Access-Control-Allow-Credentials', true);
var origin = req.headers.origin;
if (_.contains(config.allowed_origins, origin)) {
res.setHeader('Access-Control-Allow-Origin', origin);
}
if (req.method === 'OPTIONS') {
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