Plugins
Don't you just love it when time and consideration is given to make something extensible, with a suitably straightforward API and structure. We've tried to do that with this Forge Server feature.
All of the above features are written as Plugins. And you can write them too, because we plan to open source the Forge Server, just like we do with our Hammer Compiler and Anvil app and many other pieces of software that we develop.
Basically a Plugin is a module in ./plugins
directory of the Forge Server project. Each plugin is responsible for registering its own rules or conditions (in future, extra conditions are not yet implemented).
This is an example of a plugin with one rule definition:
// Index module contains registerRule function
let api = require('./index')
// Registering Redirect rule
// The second argument is callback that behaves almost like
// express middleware, except for additional `args` argument
// containing rule arguments.
//
// Example: Redirect foo "bar baz" 1337
// ==> args === [ 'foo', 'bar baz', '1337']
//
// You can access site-related data through `req.context`
// object.
api.registerRule('Redirect', (args, req, res, next) => {
const location = args[0]
// be aware arguments are strings!
const status = Number(args[1]) || 302
return res.redirect(status, location)
})
Would you be interested in writing new plugins for Forge Server? Get in touch