digitaltwin-core
Version:
Minimalist framework to collect and handle data in a Digital Twin project
27 lines • 989 B
JavaScript
/**
* Base abstract class for defining a Handler component.
* A Handler is a stateless, servable component that exposes HTTP endpoints,
* useful for on-demand computation or utility services.
*/
export class Handler {
/**
* Resolves and returns the list of servable endpoints defined on the class.
* Uses static metadata declared on the constructor (__endpoints).
* @returns A list of endpoint descriptors mapping method/path to handlers.
*/
getEndpoints() {
const config = this.getConfiguration();
const ctor = this.constructor;
const endpoints = ctor.__endpoints || [];
return endpoints.map(ep => {
const handlerFn = this[ep.handlerName].bind(this);
return {
method: ep.method,
path: ep.path,
responseType: ep.responseType || config.contentType,
handler: handlerFn
};
});
}
}
//# sourceMappingURL=handler.js.map