Created
March 6, 2017 21:28
-
-
Save rcotrina94/9b6e0a5fd397ce361d543660a1b0142d to your computer and use it in GitHub Desktop.
NodeJS server with CORS headers.
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
var socket = require('socket.io'), | |
http = require('http'), | |
server = http.createServer(function(req, res){ | |
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; | |
} | |
*/ | |
}), | |
socket = socket.listen(server); | |
socket.on('connection', function(connection) { | |
console.log('User Connected'); | |
connection.on('message', function(msg){ | |
socket.emit('message', msg); | |
}); | |
}); | |
server.listen(3000, function(){ | |
console.log('Server started'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment