Protect all Node-specific code with NODE checks

This commit is contained in:
Jeff Parsons 2017-01-02 15:16:18 -08:00 committed by Jeff Parsons
commit b5d6afd210
49 changed files with 362 additions and 282 deletions

View file

@ -38,7 +38,6 @@ if (NODE) {
var http = require("http");
var path = require("path");
var url = require("url");
var str = require("./strlib");
}
/*
@ -342,15 +341,23 @@ net.getResource = function(sURL, dataPost, fAsync, done)
var nErrorCode = -1, sResource = null, response = null;
if (net.isRemote(sURL)) {
console.log('net.getResource("' + sURL + '"): unimplemented');
/*
* TODO: This code is nothing more than a band-aid. It assumes the URL uses "http:"
* (hence the call to getFile(), which only supports HTTP GET operations), it assumes
* the requested data is UTF-8 string data (which is normally the case, because nearly
* all our requests are for JSON files), it doesn't deal with dataPost, it assumes
* that fAsync is true, and it performs very simplistic error code mapping.
*
* But, it gets the job done for what little we actually ask of it, when our machines
* are running in the Node environment.
*/
Net.getFile(sURL, "utf8", function(err, status, data) {
if (done) done(sURL, data, err? status : 0);
});
} else {
if (!sServerRoot) {
sServerRoot = path.join(path.dirname(fs.realpathSync(__filename)), "../../../");
}
/*
* TODO: Revisit why we pass back sBaseName instead of the original sURL....
*/
var sBaseName = str.getBaseName(sURL);
var sFile = path.join(sServerRoot, sURL);
if (fAsync) {
fs.readFile(sFile, {encoding: "utf8"}, function(err, s) {
@ -361,7 +368,7 @@ net.getResource = function(sURL, dataPost, fAsync, done)
sResource = s;
nErrorCode = 0;
}
if (done) done(sBaseName, sResource, nErrorCode);
if (done) done(sURL, sResource, nErrorCode);
});
} else {
try {
@ -373,7 +380,7 @@ net.getResource = function(sURL, dataPost, fAsync, done)
*/
console.log(err.message);
}
if (done) done(sBaseName, sResource, nErrorCode);
if (done) done(sURL, sResource, nErrorCode);
response = [sResource, nErrorCode];
}
}