Web Handlers
Web handlers provide a way to easily add additional routes to your Web Server.
Built in Web Handler Modules
Section titled “Built in Web Handler Modules”- WebFinger: Provides basic WebFinger (RFC7033) support.
- System General: Serves user avatars.
- NodeInfo2: Handles NodeInfo2 requests.
- ActivityPub:
Building Your Own
Section titled “Building Your Own”Skeleton
Section titled “Skeleton”Inherit from WebHandlerModule, export moduleInfo and getModule, then register your route(s) inside init():
const WebHandlerModule = require('../../core/web_handler_module');
exports.moduleInfo = { name: 'My Handler', desc: 'Does something custom', author: 'You', packageName: 'com.example.my-handler',};
exports.getModule = class MyWebHandler extends WebHandlerModule { constructor() { super(); }
init(webServer, cb) { super.init(webServer, err => { if (err) { return cb(err); }
this.webServer.addRoute({ method: 'GET', path: /^\/my-path\/?$/, handler: this._handleRequest.bind(this), });
return cb(null); }); }
_handleRequest(req, resp) { const body = JSON.stringify({ hello: 'world' }); resp.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body), }); resp.end(body); }};Enabling Your Handler
Section titled “Enabling Your Handler”Add an entry under contentServers.web.handlers in config.hjson. The key is the camelCase form of your moduleInfo.name:
contentServers: { web: { handlers: { myHandler: { enabled: true } } }}Restart ENiGMA and your route will be registered alongside the built-in handlers.