master
Dave Winer 10 years ago
parent 548caaee5c
commit 50de28abee

@ -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.

@ -1,4 +1,4 @@
var myVersion = "0.45", myProductName = "pagePark"; var myVersion = "0.46", myProductName = "Page Park";
//The MIT License (MIT) //The MIT License (MIT)
@ -29,6 +29,8 @@ var http = require ("http");
var marked = require ("marked"); var marked = require ("marked");
var dns = require ("dns"); var dns = require ("dns");
var folderPathFromEnv = process.env.pageparkFolderPath; //1/3/15 by DW
var pageParkPrefs = { var pageParkPrefs = {
myPort: 80, myPort: 80,
indexFilename: "index" 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) { function writeStats (fname, stats) {
fsSureFilePath (fname, function () { var f = getFullFilePath (fname);
fs.writeFile (fname, jsonStringify (stats), function (err) { fsSureFilePath (f, function () {
fs.writeFile (f, jsonStringify (stats), function (err) {
if (err) { if (err) {
console.log ("writeStats: error == " + err.message); 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) { fs.exists (f, function (flExists) {
if (flExists) { if (flExists) {
fs.readFile (f, function (err, data) { fs.readFile (f, function (err, data) {
@ -281,7 +298,7 @@ function readStats (f, stats, callback) {
for (var x in storedStats) { for (var x in storedStats) {
stats [x] = storedStats [x]; stats [x] = storedStats [x];
} }
writeStats (f, stats); writeStats (fname, stats);
} }
if (callback != undefined) { if (callback != undefined) {
callback (); callback ();
@ -289,7 +306,7 @@ function readStats (f, stats, callback) {
}); });
} }
else { else {
writeStats (f, stats); writeStats (fname, stats);
if (callback != undefined) { if (callback != undefined) {
callback (); callback ();
} }
@ -297,7 +314,8 @@ function readStats (f, stats, callback) {
}); });
} }
function getMarkdownTemplate (callback) { function getMarkdownTemplate (callback) {
fs.readFile (mdTemplatePath, function (err, data) { var f = getFullFilePath (mdTemplatePath);
fs.readFile (f, function (err, data) {
if (err) { if (err) {
httpReadUrl (urlDefaultTemplate, function (s) { httpReadUrl (urlDefaultTemplate, function (s) {
fs.writeFile (mdTemplatePath, s, function (err) { fs.writeFile (mdTemplatePath, s, function (err) {

Loading…
Cancel
Save