PagePark plug-ins

A plug-in is a bit of JavaScript code that handles all requests for a domain.

Background

I've wanted the ability to extend PagePark with JavaScript since the beginning, but didn't like the two methods I had found to do it.

  1. Reading the file via fs.readFile and running it through eval.

  2. Using the vm module.

There's a better way -- we use the require-from-string package.

A plug-in is a bit of JavaScript code

If the directory for a domain has a file named filter.js, we run the script and it fully determines the response to the request. The other files in the domain directory are ignored.

Three globals from the PagePark environment are accessible to the filter script:

Example

Here's an example of a simple plug-in, almost Hello World level.

https://gist.github.com/scripting/a2d4ab4275a787e912f02e0e28d354da

What I like best about it

You can iterate over changes to your plug-ins just by saving. No need to restart anything, or change some configuration file. I find it's as much fun to work on these plug-ins as it was to work on Frontier websites.

Second runner-up thing to like: You can go into the plug-ins with the debugger! That makes a world of difference. Node has no idea it's a plug-in. ;-)