Skip to content

Instantly share code, notes, and snippets.

@IgorDePaula
Forked from balupton/cors.js
Created June 5, 2019 02:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save IgorDePaula/ad2f0dc362c3064a3b399468b608b636 to your computer and use it in GitHub Desktop.
Acheiving CORS via a Node HTTP Server
// 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