Skip to content

Instantly share code, notes, and snippets.

@i0n
Created September 21, 2010 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save i0n/589208 to your computer and use it in GitHub Desktop.
Save i0n/589208 to your computer and use it in GitHub Desktop.
process.addListener('uncaughtException', function(err, stack) {
console.log('-------------------');
console.log('Exception: ' + err);
console.log(err.stack);
console.log('-------------------');
});
var http = require('http'),
io = require('socket.io'),
sys = require('sys'),
url = require('url'),
node_port = 8080,
server = http.createServer(function(request, response){
var location = url.parse(request.url, true),
params = (location.query || request.headers);
if (location.pathname == '/config.json' && request.method == "GET") {
response.writeHead(200, {
'Content-Type': 'application/x-javascript'
});
var jsonString = JSON.stringify({
port: node_port
});
response.end(jsonString);
} else {
response.writeHead(200, {'Content-Type': 'text/html'});
response.write('<h1>Hello world</h1>');
response.end();
}
});
// socket.io
server.listen(node_port);
server = io.listen(server);
server.on('connection', function(client){
sys.log('client connected');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment