mirror of https://github.com/nodejs/node.git
Finished remote module loading
parent
ad15067ea0
commit
ea290e727d
|
@ -524,7 +524,7 @@ node.http.cat = function(url, encoding, callback) {
|
|||
var uri = node.http.parseUri(url)
|
||||
var req = new node.http.Client(uri.port || 80, uri.host).get(uri.path || "/")
|
||||
req.finish(function(res) {
|
||||
var status = res.statusCode;
|
||||
var status = res.statusCode == 200 ? 0 : -1;
|
||||
res.setBodyEncoding(encoding)
|
||||
var content = ""
|
||||
res.onBody = function(chunk) {
|
||||
|
|
10
src/node.js
10
src/node.js
|
@ -80,8 +80,12 @@ node.Module = function (o) {
|
|||
if (o.path.charAt(0) == "/")
|
||||
throw "Absolute module paths are not yet supported in Node";
|
||||
|
||||
var dir = o.base_directory || ".";
|
||||
this.filename = node.path.join(dir, o.path);
|
||||
if (o.path.match(/:\/\//)) {
|
||||
this.filename = o.path;
|
||||
} else {
|
||||
var dir = o.base_directory || ".";
|
||||
this.filename = node.path.join(dir, o.path);
|
||||
}
|
||||
|
||||
this.loaded = false;
|
||||
this.exited = false;
|
||||
|
@ -93,7 +97,7 @@ node.Module.prototype.load = function (callback) {
|
|||
if (self.loaded)
|
||||
throw "Module '" + self.filename + "' is already loaded.";
|
||||
|
||||
node.fs.cat(self.filename, "utf8", function (status, content) {
|
||||
node.cat(self.filename, "utf8", function (status, content) {
|
||||
if (status != 0) {
|
||||
stderr.puts("Error reading " + self.filename);
|
||||
node.exit(1);
|
||||
|
|
|
@ -15,7 +15,12 @@ server.listen(PORT);
|
|||
function onLoad() {
|
||||
node.http.cat("http://localhost:"+PORT, "utf8", function(status, content) {
|
||||
assertEquals(body, content);
|
||||
assertEquals(200, status)
|
||||
assertEquals(0, status)
|
||||
server.close()
|
||||
})
|
||||
|
||||
node.http.cat("http://localhost:"+PORT+1, "utf8", function(status, content) {
|
||||
assertEquals(-1, status)
|
||||
assertEquals(nil, content)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ server.listen(PORT);
|
|||
function onLoad() {
|
||||
node.cat("http://localhost:"+PORT, "utf8", function(status, content) {
|
||||
assertEquals(body, content);
|
||||
assertEquals(200, status)
|
||||
assertEquals(0, status)
|
||||
server.close()
|
||||
})
|
||||
|
||||
|
@ -23,6 +23,7 @@ function onLoad() {
|
|||
var fixtures = node.path.join(dirname, "fixtures");
|
||||
var x = node.path.join(fixtures, "x.txt");
|
||||
node.cat(x, "utf8", function(status, content) {
|
||||
assertEquals(0, status)
|
||||
assertEquals("xyz", content.replace(/[\r\n]/, ''))
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
new node.http.Server(function (req, res) {
|
||||
var s = new node.http.Server(function (req, res) {
|
||||
var body = "exports.A = function() { return 'A';}";
|
||||
res.sendHeader(200, [
|
||||
["Content-Length", body.length],
|
||||
|
@ -6,7 +6,8 @@ new node.http.Server(function (req, res) {
|
|||
]);
|
||||
res.sendBody(body);
|
||||
res.finish();
|
||||
}).listen(8000);
|
||||
});
|
||||
s.listen(8000);
|
||||
|
||||
include("mjsunit.js");
|
||||
var a = require("http://localhost:8000/")
|
||||
|
@ -14,7 +15,5 @@ var a = require("http://localhost:8000/")
|
|||
function onLoad() {
|
||||
assertInstanceof(a.A, Function);
|
||||
assertEquals("A", a.A());
|
||||
|
||||
s.close();
|
||||
}
|
||||
|
||||
// TODO: Add tests for remote require using a timeout
|
Loading…
Reference in New Issue