UNPKG

backapirest

Version:

A simple API framework using Flexible Persistence

51 lines 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); // @ts-ignore class RouterSingleton { constructor(routerBase) { this.routerBase = routerBase; this.routes = routerBase?.(); } getRoutes() { return this.routes; } static getInstance() { if (!this._instance) { this._instance = new this(); } return this._instance; } getControllers() { return this.controller; } getController(name) { if (name !== undefined) return this.controller?.[name]; return this.controller; } addRoute(route, handler) { const routes = this.routes; const controller = this.controller?.[handler]; if (controller !== undefined) { const optionsM = controller?.options?.bind(controller); const createM = controller?.create?.bind(controller); const readM = controller?.read?.bind(controller); const updateM = controller?.update?.bind(controller); const deleteM = controller?.delete?.bind(controller); if (optionsM) routes.options(route, optionsM); if (createM) routes.post(route, createM); if (readM) routes.get(route, readM); if (updateM) { routes.put(route, updateM); routes.patch(route, updateM); } if (deleteM) routes.delete(route, deleteM); } } } exports.default = RouterSingleton; //# sourceMappingURL=routerSingleton.js.map