This document defines the descriptor contract loaded by bfast-function.
Function files are discovered recursively from functionsConfig.functionsDirPath and matched by extension:
.js.mjs.cjs
Each exported value is inspected. Only exports where value is an object are registered.
Loader behavior:
- tries dynamic
import() - falls back to
require()
Ignore patterns come from bfast.json.ignore when provided, otherwise defaults are used.
Required:
onRequest(req, res)
Optional:
path(string route path)method(get|post|put|patch|delete|all, defaults toall)descriptionordoc(string; shown on/functions-alldocs page)requestorrequestSample(object/string; shown as request sample on/functions-all)responseorresponseSample(object/string; shown as response sample on/functions-all)
Default route behavior:
- if
pathis omitted, route is/functions/<exportName>.
Example:
export const hello = {
method: 'get',
path: '/hello',
onRequest: (req, res) => {
res.status(200).send('ok');
}
};Required:
onGuard(req, res, next)
Optional:
path
Path behavior:
path === '/'or missing/invalid path -> mounted globally withapp.use(onGuard)- otherwise mounted at path prefix with
app.use(path, onGuard)
Example:
export const auth = {
path: '/',
onGuard: (req, res, next) => {
next();
}
};Required:
name(string)onEvent(request, response)
Behavior:
- namespace =
name - inbound event key =
name - outbound event key =
name
request shape:
{ auth, body }
response helpers:
emit(data)broadcast(data)announce(data)emitTo(socketId, data)topic(topicName).join()topic(topicName).broadcast(data)topic(topicName).announce(data)
Example:
export const chat = {
name: '/chat',
onEvent: ({ body }, response) => {
response.announce({ message: body?.message });
}
};Required:
rule(node-schedule rule)onJob()
Example:
export const everyMinute = {
rule: '* * * * *',
onJob: () => {
console.log('tick');
}
};The runtime adds two built-ins automatically:
GET /functions-health->{ "message": "running" }GET /functions-all-> HTML documentation page for discovered descriptors- add
?format=json(or sendAccept: application/json) for machine-readable JSON metadata
- add