master
Dave Winer 10 years ago
parent e8033568e1
commit 713e9f9d65

@ -17,13 +17,17 @@ It's 90 percent of what all web servers do, so if you learn how to run <a href="
2. Copy pagepark.js into that folder, and run it: node pagepark.js 2. Copy pagepark.js into that folder, and run it: node pagepark.js
#### Screen shot
Here's a <a href="http://scripting.com/2015/01/04/pageParkFolderScreenShot.png">screen shot</a> of my PagePark server folder.
#### How it works #### How it works
1. PagePark will automatically create a *prefs* sub-folder and a *domains* sub-folder. 1. PagePark will automatically create a *prefs* sub-folder and a *domains* sub-folder.
2. Add your web content under domains. Each folder's name is the name of a domain. The contents within the folder are what we serve. <a href="http://scripting.com/2015/01/04/pageParkFolderScreenShot.png">Screen shot</a>. 2. Add your web content under domains. Each folder's name is the name of a domain. The contents within the folder are what we serve. <a href="http://scripting.com/2015/01/04/pageParkFolderScreenShot.png">Screen shot</a>.
3. Serves all major media types including audio and video. Files whose names end with .md are passed through the built-in Markdown processor. Files ending with .js are interpreted as scripts. The text they return is what we serve. 3. Serves all major media types including audio and video. Files whose names end with .md are passed through the built-in Markdown processor. Files ending with .js are interpreted as scripts. The text they return is what we serve. Here's an <a href="https://gist.github.com/scripting/2b5e237a105b6cb96287">example</a> of a script that I have <a href="http://lucky.wtf/badass/butt.js">running</a> on one of my servers.
4. The prefs folder contains a file of settings you can change, prefs.json. These include the port that the server runs on and the name of the index file (see below). 4. The prefs folder contains a file of settings you can change, prefs.json. These include the port that the server runs on and the name of the index file (see below).
@ -37,9 +41,19 @@ It's 90 percent of what all web servers do, so if you learn how to run <a href="
9. There are three special endpoints on all domains: /version, /now and /status that return the version of PagePark that's running, the time on the server and the stats and prefs. 9. There are three special endpoints on all domains: /version, /now and /status that return the version of PagePark that's running, the time on the server and the stats and prefs.
#### Screen shot #### Port 1339
Here's a <a href="http://scripting.com/2015/01/04/pageParkFolderScreenShot.png">screen shot</a> of my PagePark server folder. The first time you run PagePark it will open on port 1339. You can change this by editing prefs.json in the prefs folder.
This means if you want to access a page on your site, the URL will be of the form:
http://myserver.com:1339/somepage.html
The normal port for HTTP is 80. That would have been the natural default, however a lot of Unix servers require the app to be running in supervisor mode in order for it to open on port 80. You can do this by launching PagePark this way:
sudo node pagepark.js
I made the default 1339 because I wanted it to work "out of the box" for first-time users.
#### Example pages #### Example pages
@ -71,6 +85,15 @@ There will always be more work to do here. ;-)
#### Updates #### Updates
##### v0.48 1/8/15 by DW
The default port the server boots up on is now 1339. Previously it was 80, which is the standard port for HTTP, but on many OSes this requires PagePark to be running in supervisor mode. I added docs above to explain this.
Changed package.json so that only *request* and *marked* were listed as dependencies. Apparently the others are included in Node without having to list them.
Instead of keeping our own MIME type table, we use the Node *mime* package, which is also included as a dependency in the package.json file.
##### v0.47 1/7/15 by DW ##### v0.47 1/7/15 by DW
Added a package.json file to the repository. Added a package.json file to the repository.

@ -2,16 +2,14 @@
"name": "PagePark", "name": "PagePark",
"description": "A simple Node.js folder-based HTTP server that serves static and dynamic pages for domains.", "description": "A simple Node.js folder-based HTTP server that serves static and dynamic pages for domains.",
"author": "Dave Winer <dave@smallpicture.com>", "author": "Dave Winer <dave@smallpicture.com>",
"version": "0.40.0", "version": "0.48.0",
"scripts": { "scripts": {
"start": "node pagepark.js" "start": "node pagepark.js"
}, },
"dependencies" : { "dependencies" : {
"request": "*", "request": "*",
"url": "*", "mime": "*",
"http": "*", "marked": "*"
"marked": "*",
"dns": "*"
}, },
"license": "MIT", "license": "MIT",
"engines": { "engines": {

@ -1,4 +1,4 @@
var myVersion = "0.47", myProductName = "PagePark"; var myVersion = "0.48", myProductName = "PagePark";
//The MIT License (MIT) //The MIT License (MIT)
@ -28,6 +28,7 @@ var urlpack = require ("url");
var http = require ("http"); var http = require ("http");
var marked = require ("marked"); var marked = require ("marked");
var dns = require ("dns"); var dns = require ("dns");
var mime = require ("mime"); //1/8/15 by DW
var folderPathFromEnv = process.env.pageparkFolderPath; //1/3/15 by DW var folderPathFromEnv = process.env.pageparkFolderPath; //1/3/15 by DW
@ -89,6 +90,29 @@ var urlDefaultTemplate = "http://fargo.io/code/pagepark/defaultmarkdowntemplate.
d2 = new Date (d2); d2 = new Date (d2);
return ((d1.getFullYear () == d2.getFullYear ()) && (d1.getMonth () == d2.getMonth ()) && (d1.getDate () == d2.getDate ())); return ((d1.getFullYear () == d2.getFullYear ()) && (d1.getMonth () == d2.getMonth ()) && (d1.getDate () == d2.getDate ()));
} }
function beginsWith (s, possibleBeginning, flUnicase) {
if (s.length == 0) { //1/1/14 by DW
return (false);
}
if (flUnicase == undefined) {
flUnicase = true;
}
if (flUnicase) {
for (var i = 0; i < possibleBeginning.length; i++) {
if (s [i].toLowerCase () != possibleBeginning [i].toLowerCase ()) {
return (false);
}
}
}
else {
for (var i = 0; i < possibleBeginning.length; i++) {
if (s [i] != possibleBeginning [i]) {
return (false);
}
}
}
return (true);
}
function endsWith (s, possibleEnding, flUnicase) { function endsWith (s, possibleEnding, flUnicase) {
if ((s == undefined) || (s.length == 0)) { if ((s == undefined) || (s.length == 0)) {
return (false); return (false);
@ -113,8 +137,15 @@ var urlDefaultTemplate = "http://fargo.io/code/pagepark/defaultmarkdowntemplate.
} }
return (true); return (true);
} }
function stringDelete (s, ix, ct) {
var start = ix - 1;
var end = (ix + ct) - 1;
var s1 = s.substr (0, start);
var s2 = s.substr (end);
return (s1 + s2);
}
function stringContains (s, whatItMightContain, flUnicase) { function stringContains (s, whatItMightContain, flUnicase) {
if (flUnicase == undefined) { if (flUnicase === undefined) {
flUnicase = true; flUnicase = true;
} }
if (flUnicase) { if (flUnicase) {
@ -172,56 +203,10 @@ var urlDefaultTemplate = "http://fargo.io/code/pagepark/defaultmarkdowntemplate.
return s; return s;
} }
function httpExt2MIME (ext) { //12/24/14 by DW function httpExt2MIME (ext) { //12/24/14 by DW
var lowerext = ext.toLowerCase (); mime.default_type = "text/plain";
var map = { console.log ("httpExt2MIME: type == " + mime.lookup (ext));
"au": "audio/basic", return (mime.lookup (ext));
"avi": "application/x-msvideo",
"bin": "application/x-macbinary",
"css": "text/css",
"dcr": "application/x-director",
"dir": "application/x-director",
"dll": "application/octet-stream",
"doc": "application/msword",
"dtd": "text/dtd",
"dxr": "application/x-director",
"exe": "application/octet-stream",
"fatp": "text/html",
"ftsc": "text/html",
"fttb": "text/html",
"gif": "image/gif",
"gz": "application/x-gzip",
"hqx": "application/mac-binhex40",
"htm": "text/html",
"html": "text/html",
"jpeg": "image/jpeg",
"jpg": "image/jpeg",
"js": "application/javascript",
"mid": "audio/x-midi",
"midi": "audio/x-midi",
"mov": "video/quicktime",
"mp3": "audio/mpeg",
"pdf": "application/pdf",
"png": "image/png",
"ppt": "application/mspowerpoint",
"ps": "application/postscript",
"ra": "audio/x-pn-realaudio",
"ram": "audio/x-pn-realaudio",
"sit": "application/x-stuffit",
"sys": "application/octet-stream",
"tar": "application/x-tar",
"text": "text/plain",
"txt": "text/plain",
"wav": "audio/x-wav",
"wrl": "x-world/x-vrml",
"xml": "text/xml",
"zip": "application/zip"
};
for (x in map) {
if (x.toLowerCase () == lowerext) {
return (map [x]);
}
}
return ("text/plain");
} }
function httpReadUrl (url, callback) { function httpReadUrl (url, callback) {
request (url, function (error, response, body) { request (url, function (error, response, body) {
@ -231,7 +216,8 @@ var urlDefaultTemplate = "http://fargo.io/code/pagepark/defaultmarkdowntemplate.
}); });
} }
function fsSureFilePath (path, callback) { function fsSureFilePath (path, callback) {
var splits = path.split ("/"), path = ""; var splits = path.split ("/");
path = ""; //1/8/15 by DW
if (splits.length > 0) { if (splits.length > 0) {
function doLevel (levelnum) { function doLevel (levelnum) {
if (levelnum < (splits.length - 1)) { if (levelnum < (splits.length - 1)) {

Loading…
Cancel
Save