Last active
August 29, 2015 14:05
-
-
Save yoannmoinet/74912275dca5e83081b4 to your computer and use it in GitHub Desktop.
Add all requested headers for a CORS request.
This file contains 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
//Cross Domain Headers. | |
//A bit hacky on the referer. | |
var getCorsHeaders = function (req, res){ | |
//Can't put wildcards here, | |
//so here we are, cheating all the way. | |
var ref = req.headers.referer || req.headers.origin; | |
ref = ref?ref.slice(0,-1):"*"; | |
res.set('Access-Control-Allow-Origin', ref); | |
res.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); | |
res.set('Access-Control-Allow-Headers', 'Authorization, X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, origin'); | |
res.set('Access-Control-Allow-Credentials', true); | |
res.set('Content-Type', 'application/json'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment