Fargo Publisher 0.95

New in this release is the ability to write your own request handlers in JavaScript.#

I added this feature because I wanted to try writing my own handlers without having to update Fargo Publisher. #

How it works

If a request comes in that doesn't match any of the built-in functions, we check the scripts sub-folder of the data folder. If an item matches, we eval it and return the result.#

How matching works: If the request is for /xyz then we look for xyz.js.#

We convert the request to lowercase, so that requests are case-insensitive, however the files in the folder must have all lowercase names. #

Error handling

If we don't find it, we return 404. If there's a script error we return a 503.#

Example

If the script is in count.js and the server is running at pub.fargo.io, you'd access it through this URL: http://pub.fargo.io/count. You can try it, click the link. Reload the page. Every time you load it, the count should increment.#

A picture named script.gif#

globals is a global object that you can hang persistent values on. They persist for the life of the server, when it's rebooted it's reset. You can think of it as a scratchpad. #

Read the source

Here's the source for the server. To find the part that implements this, search for 404. We look in the scripts folder before calling it a Not Found error. #

Blog post

I wrote a bit about this on Scripting News.#


Last built: Mon, Oct 13, 2014 at 6:47 AM

Show comments
By Dave Winer, Wednesday, April 23, 2014 at 2:19 PM. This aggression will not stand.