I wrote this simple Node.js folder-based HTTP server that serves static and dynamic pages for domains I've bought but not yet used.
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Dave Winer 16450deb6f v0.47 10 years ago
LICENSE Initial commit 10 years ago
README.md v0.47 10 years ago
package.json v0.47 10 years ago
pagepark.js v0.47 10 years ago

README.md

PagePark

I wrote this simple HTTP server to park domains I've bought but not yet used.

It's written in JavaScript and runs in Node.js.

Each domain is in its own folder. The content for that domain is in the folder. I went a little wild with content types, it can serve Markdown docs, or run JS code. And of course HTML, text files, images, movies, etc.

Yet it's still very simple. Which is the point. ;-)

It's 90 percent of what all web servers do, so if you learn how to run PagePark, you're learning how to run a web server. A real one you can use to host your sites. And it's easy to hack the code if you want to.

How to

  1. Create a folder to host your website.

  2. Create a sub-folder named domains.

  3. Copy pagepark.js into that folder, and run it: node pagepark.js

How it works

  1. PagePark will automatically create a prefs 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.

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

  5. stats.json contains information generated by the server including the number of times the server has started, how many hits it's received (all time and today), and hits by domain.

  6. mdTemplate.txt is the template we use to serve Markdown text. You can edit this file to provide a common template for all your Markdown documents.

  7. If a request comes in for a folder, we scan the folder for a file whose name begins with index and serve the first one we find. So the index file can be HTML, Markdown or a script, or any other type PagePark can serve.

  8. If you want to run PagePark from a folder different from the one that contains the app, set the pageparkFolderPath environment variable to point to that folder.

  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

Here's a screen shot of my PagePark server folder.

Example pages

http://noderunner.org/ -- simple home page

http://lucky.wtf/ -- images

http://lucky.wtf/test.md -- markdown page

http://lucky.wtf/badass/ -- index file in a sub-directory

http://lucky.wtf/badass/butt.js -- a page implemented in a script

http://pagepark.io/ -- the home page for this product, served by the product

http://karass.co/nosuchfile.html -- file not found

http://pagepark.io/version -- the version of PagePark that's running on the server

http://pagepark.io/now -- the time on the server

JavaScript sample code

I've iterated over the code to try to make it good sample code for JavaScript projects.

I wanted to make code that could be used for people who are just getting started with Node, to help make the process easier.

There will always be more work to do here. ;-)

Updates

v0.47 1/7/15 by DW

Fixed first time startup problem creating prefs.json and stats.json.

Also, we now make sure the domains folder exists at startup.

Fixed a problem in handling requests if you specified a different folder for PagePark to serve from.

Questions, comments?

Please post a note on the Server Snacks mail list.