You are reading content from Scuttlebutt
@cel %IG8qyOD39vCXdWmWbf7suoUiE+6FTUyMJDUOwGdtBRw=.sha256

Patchfoo scripts

Added in %vdal3tY...:f002fac331c79baff7fde57899d76be0410ffe10. This is a way to add CGI-like plugin scripts to patchfoo. The way it works is that you can put JS files in ~/.ssb/patchfoo/script/, and then call them by making requests under http://localhost:8027/script/. Each script should export a function taking a single argument which is an instance of Serve from patchfoo/lib/serve.js. The serve object has req and res properties for a HTTP request/response, and all the state and helper functions that a request handler built into patchfoo would have as in patchfoo's lib/serve.js. The scripts are loaded from the filesystem using require(). When patchfoo serves a HTTP request to a script, it will stat the script file and only reload the script if the file's mtime has changed. So you can edit scripts and refresh your browser to see changes, without having to restart a node process or wait for a build/watch process. A script can use require to load node modules that patchfoo or scuttlebot would have access to, although it does not have control over what version it gets in that case. You could also put whole packages in the ~/.ssb/patchfoo/script directory and use [ssb-]npm to manage their dependencies. It just has to be require-able and fs.stat-able to be serveable by patchfoo. But note that the auto-reload feature is only used by patchfoo for the scripts it loads; if a script requires other modules, those remain cached as usual unless you manually remove them from require.cache.

Here is an example script, which lists the longest feeds (by message count) in your ssb db (This is what I used for %/X30guQ...): longest.js

Join Scuttlebutt now