Permalink
Browse files

Update for latest node API

  • Loading branch information...
1 parent 5472c21 commit b6b13ab00b408cb5c17450ef2cccd908f6df704b @ry ry committed Oct 30, 2009
Showing with 16 additions and 13 deletions.
  1. +9 −7 fu.js
  2. +1 −1 jquery-1.2.6.min.js
  3. +6 −5 server.js
View
16 fu.js
@@ -1,3 +1,5 @@
+var createServer = require("/http.js").createServer;
+var sys = require("/sys.js");
DEBUG = false;
var fu = exports;
@@ -18,7 +20,7 @@ fu.get = function (path, handler) {
getMap[path] = handler;
};
-var server = node.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;
@@ -45,7 +47,7 @@ var server = node.http.createServer(function (req, res) {
fu.listen = function (port, host) {
server.listen(port, host);
- puts("Server at http://" + (host || "127.0.0.1") + ":" + port.toString() + "/");
+ sys.puts("Server at http://" + (host || "127.0.0.1") + ":" + port.toString() + "/");
};
fu.close = function () { server.close(); };
@@ -58,16 +60,16 @@ function extname (path) {
fu.staticHandler = function (filename) {
var body, headers;
var content_type = fu.mime.lookupExtension(extname(filename));
- var encoding = (content_type.slice(0,4) === "text" ? "utf8" : "raw");
+ var encoding = (content_type.slice(0,4) === "text" ? "utf8" : "binary");
function loadResponseData(callback) {
if (body && headers && !DEBUG) {
callback();
return;
}
- puts("loading " + filename + "...");
- var promise = node.fs.cat(filename, encoding);
+ sys.puts("loading " + filename + "...");
+ var promise = process.fs.cat(filename, encoding);
promise.addCallback(function (data) {
body = data;
@@ -77,12 +79,12 @@ fu.staticHandler = function (filename) {
if (!DEBUG)
headers.push(["Cache-Control", "public"]);
- puts("static file " + filename + " loaded");
+ sys.puts("static file " + filename + " loaded");
callback();
});
promise.addErrback(function () {
- puts("Error loading " + filename);
+ sys.puts("Error loading " + filename);
});
}
Oops, something went wrong.

0 comments on commit b6b13ab

Please sign in to comment.