Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated to node v1.3.0

  • Loading branch information...
commit 3eca54187a6073dc742de7e94c7c0acd57b77630 1 parent cb7ea87
Connor Dunn authored
Showing with 41 additions and 42 deletions.
  1. +12 −8 debug.js
  2. +29 −34 fu.js
20 debug.js
View
@@ -1,4 +1,5 @@
-var fu = require("./fu");
+var fu = require("./fu"),
+ url = require("url");
var debug = exports;
@@ -17,17 +18,19 @@ fu.get("/treeview-default.gif", fu.staticHandler("treeview-default.gif"));
fu.get("/treeview-default-line.gif", fu.staticHandler("treeview-default-line.gif"));
fu.get("/eval", function (req, res) {
- if (req.uri.params.eval !== undefined && req.uri.params.id !== undefined) {
- res.simpleJSON(200, evalStr(req.uri.params.eval, req.uri.params.id));
+ var uri = url.parse(req.url, true);
+ if (uri.query.eval !== undefined && uri.query.id !== undefined) {
+ res.simpleJSON(200, evalStr(uri.query.eval, uri.query.id));
} else {
res.simpleText(200, 'Error');
}
});
fu.get("/tree", function (req, res) {
- if (req.uri.params.id !== undefined && req.uri.params.cmd !== undefined) {
- if (req.uri.params.root !== undefined) {
- res.simpleJSON(200, getObj(req.uri.params.id, req.uri.params.cmd, req.uri.params.root));
+ var uri = url.parse(req.url, true);
+ if (uri.query.id !== undefined && uri.query.cmd !== undefined) {
+ if (uri.query.root !== undefined) {
+ res.simpleJSON(200, getObj(uri.query.id, uri.query.cmd, uri.query.root));
}
} else {
res.simpleText(200, 'Error');
@@ -35,8 +38,9 @@ fu.get("/tree", function (req, res) {
});
fu.get("/console", function (req, res) {
- if (req.uri.params.id !== undefined) {
- handleConsole(req.uri.params.id, res);
+ var uri = url.parse(req.url, true);
+ if (uri.query.id !== undefined) {
+ handleConsole(uri.query.id, res);
} else {
res.simpleText(200, 'Error');
}
63 fu.js
View
@@ -1,8 +1,7 @@
-var http = require('http'),
- sys = require('sys'),
- fs = require('fs')
-;
-
+var createServer = require("http").createServer;
+var readFile = require("fs").readFile;
+var sys = require("sys");
+var url = require("url");
DEBUG = true;
var fu = exports;
@@ -13,8 +12,8 @@ function notFound(req, res) {
res.sendHeader(404, [ ["Content-Type", "text/plain"]
, ["Content-Length", NOT_FOUND.length]
]);
- res.sendBody(NOT_FOUND);
- res.finish();
+ res.write(NOT_FOUND);
+ res.close();
}
var getMap = {};
@@ -22,17 +21,16 @@ var getMap = {};
fu.get = function (path, handler) {
getMap[path] = handler;
};
-
-var server = http.createServer(function (req, res) {
+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"]
, ["Content-Length", body.length]
]);
- res.sendBody(body);
- res.finish();
+ res.write(body);
+ res.close();
};
res.simpleJSON = function (code, obj) {
@@ -40,8 +38,8 @@ var server = http.createServer(function (req, res) {
res.sendHeader(code, [ ["Content-Type", "text/json"]
, ["Content-Length", body.length]
]);
- res.sendBody(body);
- res.finish();
+ res.write(body);
+ res.close();
};
handler(req, res);
@@ -72,31 +70,28 @@ fu.staticHandler = function (filename) {
}
sys.puts("loading " + filename + "...");
- var path = __filename.match(/(.*\/)/)[0];
- var promise = fs.cat(path + filename, encoding);
-
- promise.addCallback(function (data) {
- body = data;
- headers = [ [ "Content-Type" , content_type ]
- , [ "Content-Length" , body.length ]
- ];
- if (!DEBUG)
- headers.push(["Cache-Control", "public"]);
-
- sys.puts("static file " + filename + " loaded");
- callback();
- });
-
- promise.addErrback(function () {
- sys.puts("Error loading " + filename);
+ readFile(filename, encoding, function (err, data) {
+ if (err) {
+ sys.puts("Error loading " + filename);
+ } else {
+ body = data;
+ headers = [ [ "Content-Type" , content_type ]
+ , [ "Content-Length" , body.length ]
+ ];
+ if (!DEBUG)
+ headers.push(["Cache-Control", "public"]);
+
+ sys.puts("static file " + filename + " loaded");
+ callback();
+ }
});
}
return function (req, res) {
loadResponseData(function () {
res.sendHeader(200, headers);
- res.sendBody(body, encoding);
- res.finish();
+ res.write(body, encoding);
+ res.close();
});
}
};
@@ -107,7 +102,7 @@ fu.mime = {
lookupExtension : function(ext, fallback) {
return fu.mime.TYPES[ext.toLowerCase()] || fallback || 'application/octet-stream';
},
-
+
// List of most common mime-types, stolen from Rack.
TYPES : { ".3gp" : "video/3gpp"
, ".a" : "application/octet-stream"
Please sign in to comment.
Something went wrong with that request. Please try again.