-
-
Save arturparkhisenko/e3d1023b793ca863af7a35a724af3a36 to your computer and use it in GitHub Desktop.
Acheiving CORS via a Node HTTP Server
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
// Create our server | |
var server; | |
server = http.createServer(function(req,res){ | |
// Set CORS headers | |
res.setHeader('Access-Control-Allow-Origin', '*'); | |
res.setHeader('Access-Control-Request-Method', '*'); | |
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET'); | |
res.setHeader('Access-Control-Allow-Headers', '*'); | |
if ( req.method === 'OPTIONS' ) { | |
res.writeHead(200); | |
res.end(); | |
return; | |
} | |
// ... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment