Skip to content
Browse files

Reworked example to work with current version of node.js

  • Loading branch information...
1 parent 6c4ef86 commit 957a91aee8c58c5b1010bf8a23c17edf0d3302c1 @ulf ulf committed with ry
Showing with 12 additions and 10 deletions.
  1. +1 −1 client.js
  2. +2 −2 fu.js
  3. +9 −7 server.js
View
2 client.js
@@ -1,7 +1,7 @@
var CONFIG = { debug: false
, nick: "#" // set in onConnect
, id: null // set in onConnect
- , last_message_time: 0
+ , last_message_time: 1
};
var nicks = [];
View
4 fu.js
@@ -1,6 +1,7 @@
var createServer = require("http").createServer;
var process = require("posix");
var sys = require("sys");
+var url = require("url");
DEBUG = false;
var fu = exports;
@@ -20,10 +21,9 @@ var getMap = {};
fu.get = function (path, handler) {
getMap[path] = handler;
};
-
var server = createServer(function (req, res) {
if (req.method === "GET" || req.method === "HEAD") {
- var handler = getMap[req.uri.path] || notFound;
+ var handler = getMap[url.parse(req.url).pathname] || notFound;
res.simpleText = function (code, body) {
res.sendHeader(code, [ ["Content-Type", "text/plain"]
View
16 server.js
@@ -3,6 +3,8 @@ PORT = 8001;
var fu = require("./fu");
var sys = require("sys");
+var url = require("url");
+var qs = require("querystring");
var MESSAGE_BACKLOG = 200;
var SESSION_TIMEOUT = 60 * 1000;
@@ -129,7 +131,7 @@ fu.get("/who", function (req, res) {
});
fu.get("/join", function (req, res) {
- var nick = req.uri.params["nick"];
+ var nick = qs.parse(url.parse(req.url).query).nick;
if (nick == null || nick.length == 0) {
res.simpleJSON(400, {error: "Bad nick."});
return;
@@ -147,7 +149,7 @@ fu.get("/join", function (req, res) {
});
fu.get("/part", function (req, res) {
- var id = req.uri.params.id;
+ var id = qs.parse(url.parse(req.url).query).id;
var session;
if (id && sessions[id]) {
session = sessions[id];
@@ -157,18 +159,18 @@ fu.get("/part", function (req, res) {
});
fu.get("/recv", function (req, res) {
- if (!req.uri.params.since) {
+ if (!qs.parse(url.parse(req.url).query).since) {
res.simpleJSON(400, { error: "Must supply since parameter" });
return;
}
- var id = req.uri.params.id;
+ var id = qs.parse(url.parse(req.url).query).id;
var session;
if (id && sessions[id]) {
session = sessions[id];
session.poke();
}
- var since = parseInt(req.uri.params.since, 10);
+ var since = parseInt(qs.parse(url.parse(req.url).query).since, 10);
channel.query(since, function (messages) {
if (session) session.poke();
@@ -177,8 +179,8 @@ fu.get("/recv", function (req, res) {
});
fu.get("/send", function (req, res) {
- var id = req.uri.params.id;
- var text = req.uri.params.text;
+ var id = qs.parse(url.parse(req.url).query).id;
+ var text = qs.parse(url.parse(req.url).query).text;
var session = sessions[id];
if (!session || !text) {

0 comments on commit 957a91a

Please sign in to comment.
Something went wrong with that request. Please try again.