Created
April 12, 2016 05:28
-
-
Save bekatom/0672e967ec734f64c9563eb64122f638 to your computer and use it in GitHub Desktop.
AllowCrossDomain Request , in multiple site only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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