diff --git a/README.md b/README.md index a3acfad..8b4bf30 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,28 @@ -pagePark -======== +Page Park +========= + +A simple folder-based HTTP server that serves as a place for "parking" simple static sites for domains I've bought but not yet used. + +This is the second of three early 2015 "server snacks" by Dave Winer. + +#### Basic features + +xxx + +#### How it works + +xxx + +#### Example URLs + +http://noderunnder.org/ -- simple home page + +http://lucky.wtf/ -- images + +http://lucky.wtf/badass/ -- index file in a sub-directory + +http://lucky.wtf/badass/butt.js -- a page implemented in a script + +http://karass.co/ -- file not found + -A simple folder-based HTTP server that serves as a place for simple static sites for domains I've bought but not yet used. diff --git a/pagepark.js b/pagepark.js index 0bc9fe9..6467559 100644 --- a/pagepark.js +++ b/pagepark.js @@ -1,4 +1,4 @@ -var myVersion = "0.45", myProductName = "pagePark"; +var myVersion = "0.46", myProductName = "Page Park"; //The MIT License (MIT) @@ -29,6 +29,8 @@ var http = require ("http"); var marked = require ("marked"); var dns = require ("dns"); +var folderPathFromEnv = process.env.pageparkFolderPath; //1/3/15 by DW + var pageParkPrefs = { myPort: 80, indexFilename: "index" @@ -260,16 +262,31 @@ var urlDefaultTemplate = "http://fargo.io/code/pagepark/defaultmarkdowntemplate. } } +function getFullFilePath (relpath) { //1/3/15 by DW + var folderpath = folderPathFromEnv; + if (folderpath == undefined) { //the environment variable wasn't specified + return (relpath); + } + if (!endsWith (folderpath, "/")) { + folderpath += "/"; + } + if (beginsWith (relpath, "/")) { + relpath = stringDelete (relpath, 1, 1); + } + return (folderpath + relpath); + } function writeStats (fname, stats) { - fsSureFilePath (fname, function () { - fs.writeFile (fname, jsonStringify (stats), function (err) { + var f = getFullFilePath (fname); + fsSureFilePath (f, function () { + fs.writeFile (f, jsonStringify (stats), function (err) { if (err) { console.log ("writeStats: error == " + err.message); } }); }); } -function readStats (f, stats, callback) { +function readStats (fname, stats, callback) { + var f = getFullFilePath (fname); fs.exists (f, function (flExists) { if (flExists) { fs.readFile (f, function (err, data) { @@ -281,7 +298,7 @@ function readStats (f, stats, callback) { for (var x in storedStats) { stats [x] = storedStats [x]; } - writeStats (f, stats); + writeStats (fname, stats); } if (callback != undefined) { callback (); @@ -289,7 +306,7 @@ function readStats (f, stats, callback) { }); } else { - writeStats (f, stats); + writeStats (fname, stats); if (callback != undefined) { callback (); } @@ -297,7 +314,8 @@ function readStats (f, stats, callback) { }); } function getMarkdownTemplate (callback) { - fs.readFile (mdTemplatePath, function (err, data) { + var f = getFullFilePath (mdTemplatePath); + fs.readFile (f, function (err, data) { if (err) { httpReadUrl (urlDefaultTemplate, function (s) { fs.writeFile (mdTemplatePath, s, function (err) {