-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add url tracking functionality to browser. Also prevent http requests…
… being processed twice on certain versions of Node.
- Loading branch information
Showing
5 changed files
with
67 additions
and
43 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
*~ | ||
*~ | ||
.directory |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,4 @@ textarea#channel_box { | |
|
||
input#text_input { | ||
width: 90%; | ||
} | ||
|
||
input#submit { | ||
width: 5%; | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,50 @@ | ||
var static = require('node-static'), | ||
http = require('http'), | ||
util = require('util'), | ||
socket = require('socket.io'); | ||
http = require('http'), | ||
util = require('util'), | ||
socket = require('socket.io'); | ||
|
||
var webroot = "./client", | ||
port = 8000; | ||
port = 8000; | ||
|
||
var file = new(static.Server)(webroot, { | ||
cache: 0 | ||
cache: 0 | ||
}); | ||
|
||
var app = http.createServer(function(req, res) { | ||
req.addListener('end', function() { | ||
file.serve(req, res, function(err, result) { | ||
if (err) { | ||
console.error('Error serving %s - %s', req.url, err.message); | ||
if (err.status === 404 || err.status === 500) { | ||
file.serveFile(util.format('/%d.html', err.status), err.status, {}, req, res); | ||
} else { | ||
res.writeHead(err.status, err.headers); | ||
res.end(); | ||
} | ||
} else { | ||
console.log('%s - %s', req.url, res.message); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
app.listen(port); | ||
function requestHandler(req, res) { | ||
req.addListener('end', function() { | ||
file.serve(req, res, function(err, result) { | ||
if (err) { | ||
console.error('Error serving %s - %s', req.url, err.message); | ||
if (err.status === 404 || err.status === 500) { | ||
file.serveFile(util.format('/%d.html', err.status), err.status, {}, req, res); | ||
} else { | ||
res.writeHead(err.status, err.headers); | ||
res.end(); | ||
} | ||
} else { | ||
console.log('%s - %s', req.url, result.message); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
var app = http.createServer(requestHandler); | ||
var io = socket.listen(app); | ||
|
||
|
||
|
||
io.sockets.on('connection', function (socket) { | ||
socket.emit('join', {'name': socket.id}); | ||
socket.emit('join', {'name': socket.id}); | ||
|
||
socket.on('say', function(data) { | ||
socket.broadcast.emit('msg', {name: socket.id, msg: data.msg}); | ||
socket.emit('msg', {name: socket.id, msg: data.msg}); | ||
}); | ||
socket.on('say', function(data) { | ||
socket.broadcast.emit('msg', {name: socket.id, msg: data.msg}); | ||
socket.emit('msg', {name: socket.id, msg: data.msg}); | ||
}); | ||
}); | ||
|
||
//Work around a bug in socket.io - it delegates old handlers correctly | ||
//but fails to remove them in versions of node.js. See: | ||
// https://github.com/LearnBoost/socket.io/pull/1080 | ||
// https://github.com/LearnBoost/socket.io/issues/987 | ||
app.removeListener('request', requestHandler); | ||
|
||
app.listen(port); |