The backend server can be extended with generic or application-specific modules.
Modules are enabled in the configuration file, or using the configure-modules helper script.
To list all modules, type:
./configure-module
To enable, disable or remove modules, type:
./configure-module enable PdfUniteRequests ./configure-module disable SvgToPdfRequests ./configure-module disable ZipRequests
Restart the backend server to apply the changes:
sudo systemctl restart GenericBackendService
A module has the following structure:
httpRequestHandlers.push(new ExampleRequests(data, temporaryFolder));
function ExampleRequests(data, temporaryFolder) {
this.onHttpRequest = function(r) {
return r.handleUrl('/backend/my', {post, postPreflight});
function postPreflight(onDone) {
data.accounts.allowForGlobalOrigins(r, 'POST');
onDone();
}
function post() {
data.accounts.readAccountAndData(r, MINUTE, ready);
function ready(account, bytes) {
if (! account.allowForOrigins(r, 'POST')) return r.forbidden('Invalid origin.');
if (! account.configuration.child('example').boolean()) return r.forbidden('Missing "example" permission.');
const message = data.query.parseBytes(bytes);
const a = message.child('a').number();
const b = message.child('b').number();
if (isNaN(a)) return r.badRequest('Invalid A.');
if (isNaN(B)) return r.badRequest('Invalid B.');
r.replyWithJson(200, {product: a * b});
}
}
};
}