@bull-board/hono
Advanced tools
Comparing version 5.21.7 to 5.22.0
@@ -41,3 +41,2 @@ import type { AppControllerRoute, AppViewRoute, BullBoardQueues, ControllerHandlerReturnType, IServerAdapter, UIConfig } from '@bull-board/api/dist/typings/app'; | ||
setApiRoutes(routes: readonly AppControllerRoute[]): this; | ||
private registerRoute; | ||
setEntryRoute(routeDef: AppViewRoute): this; | ||
@@ -47,2 +46,3 @@ setQueues(bullBoardQueues: BullBoardQueues): this; | ||
registerPlugin(): Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">; | ||
private registerRoute; | ||
} |
@@ -7,5 +7,5 @@ "use strict"; | ||
exports.HonoAdapter = void 0; | ||
const node_path_1 = __importDefault(require("node:path")); | ||
const ejs_1 = __importDefault(require("ejs")); | ||
const hono_1 = require("hono"); | ||
const node_path_1 = __importDefault(require("node:path")); | ||
class HonoAdapter { | ||
@@ -56,43 +56,2 @@ constructor(serveStatic, | ||
} | ||
registerRoute(routeOrRoutes, method, handler) { | ||
const { bullBoardQueues } = this; | ||
if (!bullBoardQueues) { | ||
throw new Error(`Please call 'setQueues' before using 'registerPlugin'`); | ||
} | ||
const routes = Array.isArray(routeOrRoutes) ? routeOrRoutes : [routeOrRoutes]; | ||
routes.forEach((route) => { | ||
this.apiRoutes[method](route, async (c) => { | ||
let reqBody = {}; | ||
if (method !== 'get') { | ||
// Safely attempt to parse the request body, since the UI does not include a request body with most requests | ||
try { | ||
reqBody = await c.req.json(); | ||
} | ||
catch { } | ||
} | ||
try { | ||
const response = await handler({ | ||
queues: bullBoardQueues, | ||
params: c.req.param(), | ||
query: c.req.query(), | ||
body: reqBody, | ||
}); | ||
if (response.status == 204) { | ||
return c.body(null, 204); | ||
} | ||
return c.json(response.body, response.status || 200); | ||
} | ||
catch (e) { | ||
if (!this.errorHandler || !(e instanceof Error)) { | ||
throw e; | ||
} | ||
const response = this.errorHandler(e); | ||
if (typeof response.body === 'string') { | ||
return c.text(response.body, response.status); | ||
} | ||
return c.json(response.body, response.status); | ||
} | ||
}); | ||
}); | ||
} | ||
setEntryRoute(routeDef) { | ||
@@ -146,4 +105,45 @@ this.entryRoute = routeDef; | ||
} | ||
registerRoute(routeOrRoutes, method, handler) { | ||
const { bullBoardQueues } = this; | ||
if (!bullBoardQueues) { | ||
throw new Error(`Please call 'setQueues' before using 'registerPlugin'`); | ||
} | ||
const routes = Array.isArray(routeOrRoutes) ? routeOrRoutes : [routeOrRoutes]; | ||
routes.forEach((route) => { | ||
this.apiRoutes[method](route, async (c) => { | ||
let reqBody = {}; | ||
if (method !== 'get') { | ||
// Safely attempt to parse the request body, since the UI does not include a request body with most requests | ||
try { | ||
reqBody = await c.req.json(); | ||
} | ||
catch { } | ||
} | ||
try { | ||
const response = await handler({ | ||
queues: bullBoardQueues, | ||
params: c.req.param(), | ||
query: c.req.query(), | ||
body: reqBody, | ||
}); | ||
if (response.status == 204) { | ||
return c.body(null, 204); | ||
} | ||
return c.json(response.body, response.status || 200); | ||
} | ||
catch (e) { | ||
if (!this.errorHandler || !(e instanceof Error)) { | ||
throw e; | ||
} | ||
const response = this.errorHandler(e); | ||
if (typeof response.body === 'string') { | ||
return c.text(response.body, response.status); | ||
} | ||
return c.json(response.body, response.status); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
exports.HonoAdapter = HonoAdapter; | ||
//# sourceMappingURL=HonoAdapter.js.map |
{ | ||
"name": "@bull-board/hono", | ||
"version": "5.21.7", | ||
"version": "5.22.0", | ||
"description": "A Hono server adapter for Bull-Board dashboard.", | ||
@@ -31,4 +31,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@bull-board/api": "5.21.7", | ||
"@bull-board/ui": "5.21.7", | ||
"@bull-board/api": "5.22.0", | ||
"@bull-board/ui": "5.22.0", | ||
"ejs": "^3.1.10", | ||
@@ -35,0 +35,0 @@ "hono": "^4.4.7" |
Sorry, the diff of this file is not supported yet
15064
+ Added@bull-board/api@5.22.0(transitive)
+ Added@bull-board/ui@5.22.0(transitive)
- Removed@bull-board/api@5.21.7(transitive)
- Removed@bull-board/ui@5.21.7(transitive)
Updated@bull-board/api@5.22.0
Updated@bull-board/ui@5.22.0