diff --git a/README.md b/README.md index a001eeb..bbae27d 100644 --- a/README.md +++ b/README.md @@ -17,13 +17,17 @@ It's 90 percent of what all web servers do, so if you learn how to run screen shot of my PagePark server folder. + #### How it works 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. Screen shot. -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 example of a script that I have running 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). @@ -37,9 +41,19 @@ It's 90 percent of what all web servers do, so if you learn how to run screen shot 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 @@ -71,6 +85,15 @@ There will always be more work to do here. ;-) #### 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 Added a package.json file to the repository. diff --git a/package.json b/package.json index 4abfa1b..456a50f 100755 --- a/package.json +++ b/package.json @@ -2,16 +2,14 @@ "name": "PagePark", "description": "A simple Node.js folder-based HTTP server that serves static and dynamic pages for domains.", "author": "Dave Winer ", - "version": "0.40.0", + "version": "0.48.0", "scripts": { "start": "node pagepark.js" }, "dependencies" : { "request": "*", - "url": "*", - "http": "*", - "marked": "*", - "dns": "*" + "mime": "*", + "marked": "*" }, "license": "MIT", "engines": { diff --git a/pagepark.js b/pagepark.js index 8d1075f..581c4bb 100644 --- a/pagepark.js +++ b/pagepark.js @@ -1,4 +1,4 @@ -var myVersion = "0.47", myProductName = "PagePark"; +var myVersion = "0.48", myProductName = "PagePark"; //The MIT License (MIT) @@ -28,6 +28,7 @@ var urlpack = require ("url"); var http = require ("http"); var marked = require ("marked"); var dns = require ("dns"); +var mime = require ("mime"); //1/8/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); 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) { if ((s == undefined) || (s.length == 0)) { return (false); @@ -113,8 +137,15 @@ var urlDefaultTemplate = "http://fargo.io/code/pagepark/defaultmarkdowntemplate. } 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) { - if (flUnicase == undefined) { + if (flUnicase === undefined) { flUnicase = true; } if (flUnicase) { @@ -172,56 +203,10 @@ var urlDefaultTemplate = "http://fargo.io/code/pagepark/defaultmarkdowntemplate. return s; } function httpExt2MIME (ext) { //12/24/14 by DW - var lowerext = ext.toLowerCase (); - var map = { - "au": "audio/basic", - "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"); + mime.default_type = "text/plain"; + console.log ("httpExt2MIME: type == " + mime.lookup (ext)); + return (mime.lookup (ext)); + } function httpReadUrl (url, callback) { request (url, function (error, response, body) { @@ -231,7 +216,8 @@ var urlDefaultTemplate = "http://fargo.io/code/pagepark/defaultmarkdowntemplate. }); } function fsSureFilePath (path, callback) { - var splits = path.split ("/"), path = ""; + var splits = path.split ("/"); + path = ""; //1/8/15 by DW if (splits.length > 0) { function doLevel (levelnum) { if (levelnum < (splits.length - 1)) {