master
Dave Winer 9 years ago
parent 60c47cd8c9
commit 6be79cdd32

@ -84,6 +84,10 @@ There will always be more work to do here. ;-)
#### Updates #### Updates
##### v0.56 5/5/15 by DW
New prefs and config values that allow you to disable processing of scripts and Markdown files. By setting the values in prefs.json, you control all domains on the server. And by adding the values to config.json, in the folder the site is served from, you can turn them off selectively by site. I needed to turn off script processing for .js files served from <a href="https://github.com/scripting/river4">River4</a>, to make it possible to serve a full river from PagePark.
##### v0.55 4/26/15 by DW ##### v0.55 4/26/15 by DW
With this release you can serve domains whose content is stored elsewhere on the web. With this release you can serve domains whose content is stored elsewhere on the web.

@ -412,6 +412,14 @@ function stringPopLastField (s, chdelim) { //5/28/14 by DW
} }
return (s); return (s);
} }
function stringPopExtension (s) { //4/29/15 by DW
for (var i = s.length - 1; i >= 0; i--) {
if (s [i] == ".") {
return (stringMid (s, 1, i));
}
}
return (s);
}
function filledString (ch, ct) { //6/4/14 by DW function filledString (ch, ct) { //6/4/14 by DW
var s = ""; var s = "";
for (var i = 0; i < ct; i++) { for (var i = 0; i < ct; i++) {

@ -1,4 +1,4 @@
var myVersion = "0.55", myProductName = "PagePark"; var myVersion = "0.56", myProductName = "PagePark";
//The MIT License (MIT) //The MIT License (MIT)
@ -35,7 +35,9 @@ var folderPathFromEnv = process.env.pageparkFolderPath; //1/3/15 by DW
var pageparkPrefs = { var pageparkPrefs = {
myPort: 1339, //1/8/15 by DW -- was 80, see note in readme.md myPort: 1339, //1/8/15 by DW -- was 80, see note in readme.md
indexFilename: "index" indexFilename: "index",
flProcessScriptFiles: true, extScriptFiles: "js", //5/5/15 by DW
flProcessMarkdownFiles: true, extMarkdownFiles: "md" //5/5/15 by DW
}; };
var fnamePrefs = "prefs/prefs.json"; var fnamePrefs = "prefs/prefs.json";
@ -152,31 +154,39 @@ function checkPathForIllegalChars (path) {
} }
return (true); return (true);
} }
function everySecond () { function everySecond () {
if (flStatsDirty) { if (flStatsDirty) {
writeStats (fnameStats, pageparkStats); writeStats (fnameStats, pageparkStats);
flStatsDirty = false; flStatsDirty = false;
} }
} }
function handleHttpRequest (httpRequest, httpResponse) { function handleHttpRequest (httpRequest, httpResponse) {
function getConfigFile (host, callback) { function getConfigFile (host, callback) {
var config = {
urlSiteRedirect: undefined,
urlSiteContents: undefined,
flProcessScriptFiles: true,
flProcessMarkdownFiles: true,
extScriptFiles: pageparkPrefs.extScriptFiles,
extMarkdownFiles: pageparkPrefs.extMarkdownFiles
};
var f = getFullFilePath (domainsPath) + host + configFname; var f = getFullFilePath (domainsPath) + host + configFname;
fs.readFile (f, function (err, data) { fs.readFile (f, function (err, data) {
if (err) { if (err) {
callback (undefined); callback (config);
} }
else { else {
try { try {
var config = JSON.parse (data.toString ()); var storedConfig = JSON.parse (data.toString ());
for (var x in storedConfig) {
config [x] = storedConfig [x];
}
callback (config); callback (config);
} }
catch (err) { catch (err) {
console.log ("getConfigFile: error reading " + configFname + " file for host " + host + ". " + err.message); console.log ("getConfigFile: error reading " + configFname + " file for host " + host + ". " + err.message);
callback (undefined); callback (config);
} }
} }
}); });
@ -199,11 +209,17 @@ function handleHttpRequest (httpRequest, httpResponse) {
return404 (); return404 ();
}); });
} }
function serveFile (f) { function serveFile (f, config) {
function httpReturn (val, type) { //2/17/15 by DW function httpReturn (val, type) { //2/17/15 by DW
httpResponse.writeHead (200, {"Content-Type": type}); httpResponse.writeHead (200, {"Content-Type": type});
httpResponse.end (val.toString ()); httpResponse.end (val.toString ());
} }
function defaultReturn (type, data) {
httpResponse.writeHead (200, {"Content-Type": type});
httpResponse.end (data);
}
fs.readFile (f, function (err, data) { fs.readFile (f, function (err, data) {
if (err) { if (err) {
return404 (); return404 ();
@ -211,32 +227,41 @@ function handleHttpRequest (httpRequest, httpResponse) {
else { else {
var ext = utils.stringLastField (f, ".").toLowerCase (), type = httpExt2MIME (ext); var ext = utils.stringLastField (f, ".").toLowerCase (), type = httpExt2MIME (ext);
switch (ext) { switch (ext) {
case "js": case config.extScriptFiles:
try { if (pageparkPrefs.flProcessScriptFiles && config.flProcessScriptFiles) {
var val = eval (data.toString ()); try {
if (val !== undefined) { //2/17/15 by DW var val = eval (data.toString ());
httpResponse.writeHead (200, {"Content-Type": "text/html"}); if (val !== undefined) { //2/17/15 by DW
httpResponse.end (val.toString ()); httpResponse.writeHead (200, {"Content-Type": "text/html"});
httpResponse.end (val.toString ());
}
}
catch (err) {
httpResponse.writeHead (500, {"Content-Type": "text/plain"});
httpResponse.end ("Error running " + parsedUrl.pathname + ": \"" + err.message + "\"");
} }
} }
catch (err) { else {
httpResponse.writeHead (500, {"Content-Type": "text/plain"}); defaultReturn (type, data);
httpResponse.end ("Error running " + parsedUrl.pathname + ": \"" + err.message + "\"");
} }
break; break;
case "md": case config.extMarkdownFiles:
getMarkdownTemplate (function (theTemplate) { if (pageparkPrefs.flProcessMarkdownFiles && config.flProcessMarkdownFiles) {
var mdtext = data.toString (), pagetable = new Object (); getMarkdownTemplate (function (theTemplate) {
pagetable.bodytext = marked (mdtext); var mdtext = data.toString (), pagetable = new Object ();
pagetable.title = utils.stringLastField (f, "/"); pagetable.bodytext = marked (mdtext);
var s = utils.multipleReplaceAll (theTemplate, pagetable, false, "[%", "%]"); pagetable.title = utils.stringLastField (f, "/");
httpResponse.writeHead (200, {"Content-Type": "text/html"}); var s = utils.multipleReplaceAll (theTemplate, pagetable, false, "[%", "%]");
httpResponse.end (s); httpResponse.writeHead (200, {"Content-Type": "text/html"});
}); httpResponse.end (s);
});
}
else {
defaultReturn (type, data);
}
break; break;
default: default:
httpResponse.writeHead (200, {"Content-Type": type}); defaultReturn (type, data);
httpResponse.end (data);
break; break;
} }
} }
@ -343,11 +368,11 @@ function handleHttpRequest (httpRequest, httpResponse) {
f += "/"; f += "/";
} }
findIndexFile (f, function (findex) { findIndexFile (f, function (findex) {
serveFile (findex); serveFile (findex, config);
}); });
} }
else { else {
serveFile (f); serveFile (f, config);
} }
} }
}); });
@ -366,8 +391,6 @@ function handleHttpRequest (httpRequest, httpResponse) {
httpResponse.end (tryError.message); httpResponse.end (tryError.message);
} }
} }
function writeStats (fname, stats, callback) { function writeStats (fname, stats, callback) {
var f = getFullFilePath (fname); var f = getFullFilePath (fname);
fsSureFilePath (f, function () { fsSureFilePath (f, function () {
@ -416,8 +439,6 @@ function readStats (fname, stats, callback) {
}); });
}); });
} }
function startup () { function startup () {
readStats (fnamePrefs, pageparkPrefs, function () { readStats (fnamePrefs, pageparkPrefs, function () {
readStats (fnameStats, pageparkStats, function () { readStats (fnameStats, pageparkStats, function () {

Loading…
Cancel
Save