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.
pagePark/README.md

123 lines
6.3 KiB
Markdown

9 years ago
#### PagePark
10 years ago
I wrote this simple HTTP server to park domains I've bought but not yet used.
10 years ago
10 years ago
It's written in JavaScript and runs in Node.js.
10 years ago
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. ;-)
10 years ago
It's 90 percent of what all web servers do, so if you learn how to run <a href="http://pagepark.io/">PagePark</a>, 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.
10 years ago
10 years ago
#### How to
1. Create a folder to host your website.
10 years ago
10 years ago
2. Copy pagepark.js into that folder, and run it: node pagepark.js
10 years ago
10 years ago
#### Screen shot
Here's a <a href="http://scripting.com/2015/01/04/pageParkFolderScreenShot.png">screen shot</a> of my PagePark server folder.
10 years ago
#### How it works
10 years ago
10 years ago
1. PagePark will automatically create a *prefs* sub-folder and a *domains* sub-folder.
10 years ago
10 years ago
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>.
10 years ago
10 years ago
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.
10 years ago
10 years ago
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).
10 years ago
10 years ago
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.
10 years ago
10 years ago
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.
10 years ago
10 years ago
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.
10 years ago
10 years ago
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.
10 years ago
10 years ago
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.
10 years ago
10 years ago
#### Port 1339
10 years ago
10 years ago
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.
10 years ago
#### Example pages
10 years ago
10 years ago
http://noderunner.org/ -- simple home page
10 years ago
http://lucky.wtf/ -- images
10 years ago
http://lucky.wtf/test.md -- markdown page
10 years ago
http://lucky.wtf/badass/ -- index file in a sub-directory
http://lucky.wtf/badass/butt.js -- a page implemented in a script
10 years ago
http://pagepark.io/ -- the home page for this product, served by the product
10 years ago
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. ;-)
10 years ago
10 years ago
#### Updates
9 years ago
##### v0.54 2/18/15 by DW
A new feature for pages implemented as scripts. If the script returns the value <i>undefined</i> PagePark will not return a value to the HTTP client, it assumes that the script will do this.
To make it possible for a script page to return a value to the client, there's a new built-in function httpReturn. It takes two parameters, the value, a string, and the type, a MIME type. For example you might have a script that makes an HTTP request and returns a value based on the result to the caller.
Here's an <a href="https://gist.github.com/scripting/a3a8232d193ea88e04ba">example script</a> that illustrates.
9 years ago
##### v0.51 1/18/15 by DW
Created utils.js in the lib folder, and require it in pagepark.js.
9 years ago
New feature: If there's a file called config.json in a domain folder, we read it on every request, and values in that file can change the behavior of the server. The first feature allows you to do a whole-site redirect. Useful if you want to have several names map to the same content. Here's an <a href="https://gist.github.com/scripting/27be2d8be40577ad0fdf">example</a> of the config.json file that maps a domain to <a href="http://nodestorage.io/">nodestorage.io</a>.
9 years ago
10 years ago
##### 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.
10 years ago
##### v0.47 1/7/15 by DW
10 years ago
Added a package.json file to the repository.
Fixed first-time startup problem creating prefs.json and stats.json.
10 years ago
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.
10 years ago
#### Questions, comments?
10 years ago
10 years ago
Please post a note on the <a href="https://groups.google.com/forum/#!forum/server-snacks">Server Snacks</a> mail list.
9 years ago