@bull-board/hono 5.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/dist/HonoAdapter.d.ts +30 -0
- package/dist/HonoAdapter.js +123 -0
- package/dist/HonoAdapter.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# <img alt="@bull-board" src="https://raw.githubusercontent.com/felixmosh/bull-board/master/packages/ui/src/static/images/logo.svg" width="35px" /> @bull-board/hono
|
|
2
|
+
|
|
3
|
+
[Hono](https://hono.dev) server adapter for `bull-board`.
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://www.npmjs.com/package/@bull-board/hono">
|
|
7
|
+
<img alt="npm version" src="https://img.shields.io/npm/v/@bull-board/hono">
|
|
8
|
+
</a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/bull-board">
|
|
10
|
+
<img alt="npm downloads" src="https://img.shields.io/npm/dw/bull-board">
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://github.com/felixmosh/bull-board/blob/master/LICENSE">
|
|
13
|
+
<img alt="licence" src="https://img.shields.io/github/license/felixmosh/bull-board">
|
|
14
|
+
</a>
|
|
15
|
+
<p>
|
|
16
|
+
|
|
17
|
+

|
|
18
|
+

|
|
19
|
+
|
|
20
|
+
# Usage examples
|
|
21
|
+
|
|
22
|
+
1. [Simple Hono setup](https://github.com/felixmosh/bull-board/tree/master/examples/with-hono)
|
|
23
|
+
|
|
24
|
+
For more info visit the main [README](https://github.com/felixmosh/bull-board#readme)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AppControllerRoute, AppViewRoute, BullBoardQueues, ControllerHandlerReturnType, IServerAdapter, UIConfig } from '@bull-board/api/dist/typings/app';
|
|
2
|
+
import type { serveStatic as nodeServeStatic } from '@hono/node-server/serve-static';
|
|
3
|
+
import { Hono } from 'hono';
|
|
4
|
+
import type { serveStatic as bunServeStatic } from 'hono/bun';
|
|
5
|
+
import type { serveStatic as cloudflarePagesServeStatic } from 'hono/cloudflare-pages';
|
|
6
|
+
import type { serveStatic as cloudflareWorkersServeStatic } from 'hono/cloudflare-workers';
|
|
7
|
+
import type { serveStatic as denoServeStatic } from 'hono/deno';
|
|
8
|
+
export declare class HonoAdapter implements IServerAdapter {
|
|
9
|
+
protected serveStatic: typeof bunServeStatic | typeof nodeServeStatic | typeof cloudflarePagesServeStatic | typeof cloudflareWorkersServeStatic | typeof denoServeStatic;
|
|
10
|
+
protected bullBoardQueues: BullBoardQueues | undefined;
|
|
11
|
+
protected errorHandler: ((error: Error) => ControllerHandlerReturnType) | undefined;
|
|
12
|
+
protected uiConfig?: UIConfig;
|
|
13
|
+
protected staticRoute?: string;
|
|
14
|
+
protected staticPath?: string;
|
|
15
|
+
protected entryRoute?: AppViewRoute;
|
|
16
|
+
protected viewPath?: string;
|
|
17
|
+
protected apiRoutes: Hono;
|
|
18
|
+
protected basePath: string;
|
|
19
|
+
constructor(serveStatic: typeof bunServeStatic | typeof nodeServeStatic | typeof cloudflarePagesServeStatic | typeof cloudflareWorkersServeStatic | typeof denoServeStatic);
|
|
20
|
+
setBasePath(path: string): this;
|
|
21
|
+
setStaticPath(staticRoute: string, staticPath: string): this;
|
|
22
|
+
setViewsPath(viewPath: string): this;
|
|
23
|
+
setErrorHandler(handler: (error: Error) => ControllerHandlerReturnType): this;
|
|
24
|
+
setApiRoutes(routes: readonly AppControllerRoute[]): this;
|
|
25
|
+
private registerRoute;
|
|
26
|
+
setEntryRoute(routeDef: AppViewRoute): this;
|
|
27
|
+
setQueues(bullBoardQueues: BullBoardQueues): this;
|
|
28
|
+
setUIConfig(config: UIConfig): this;
|
|
29
|
+
registerPlugin(): Hono<import("hono").Env, {}, "/">;
|
|
30
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HonoAdapter = void 0;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const ejs_1 = __importDefault(require("ejs"));
|
|
9
|
+
const hono_1 = require("hono");
|
|
10
|
+
class HonoAdapter {
|
|
11
|
+
constructor(serveStatic) {
|
|
12
|
+
this.serveStatic = serveStatic;
|
|
13
|
+
this.basePath = '/';
|
|
14
|
+
this.apiRoutes = new hono_1.Hono();
|
|
15
|
+
}
|
|
16
|
+
setBasePath(path) {
|
|
17
|
+
this.basePath = path;
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
setStaticPath(staticRoute, staticPath) {
|
|
21
|
+
this.staticRoute = staticRoute;
|
|
22
|
+
this.staticPath = staticPath;
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
setViewsPath(viewPath) {
|
|
26
|
+
this.viewPath = viewPath;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
setErrorHandler(handler) {
|
|
30
|
+
this.errorHandler = handler;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
setApiRoutes(routes) {
|
|
34
|
+
const { errorHandler, bullBoardQueues } = this;
|
|
35
|
+
if (!errorHandler || !bullBoardQueues) {
|
|
36
|
+
throw new Error('');
|
|
37
|
+
}
|
|
38
|
+
routes.forEach(({ method: methodOrMethods, route, handler }) => {
|
|
39
|
+
const methods = Array.isArray(methodOrMethods) ? methodOrMethods : [methodOrMethods];
|
|
40
|
+
methods.forEach((m) => {
|
|
41
|
+
this.registerRoute(route, m, handler);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
registerRoute(routeOrRoutes, method, handler) {
|
|
47
|
+
const { bullBoardQueues } = this;
|
|
48
|
+
if (!bullBoardQueues) {
|
|
49
|
+
throw new Error(`Please call 'setQueues' before using 'registerPlugin'`);
|
|
50
|
+
}
|
|
51
|
+
const routes = Array.isArray(routeOrRoutes) ? routeOrRoutes : [routeOrRoutes];
|
|
52
|
+
routes.forEach((route) => {
|
|
53
|
+
this.apiRoutes[method](route, async (c) => {
|
|
54
|
+
try {
|
|
55
|
+
const response = await handler({
|
|
56
|
+
queues: bullBoardQueues,
|
|
57
|
+
params: c.req.param(),
|
|
58
|
+
query: c.req.query(),
|
|
59
|
+
});
|
|
60
|
+
return c.json(response.body, response.status || 200);
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
if (!this.errorHandler || !(e instanceof Error)) {
|
|
64
|
+
throw e;
|
|
65
|
+
}
|
|
66
|
+
const response = this.errorHandler(e);
|
|
67
|
+
if (typeof response.body === 'string') {
|
|
68
|
+
return c.text(response.body, response.status);
|
|
69
|
+
}
|
|
70
|
+
return c.json(response.body, response.status);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
setEntryRoute(routeDef) {
|
|
76
|
+
this.entryRoute = routeDef;
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
setQueues(bullBoardQueues) {
|
|
80
|
+
this.bullBoardQueues = bullBoardQueues;
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
setUIConfig(config) {
|
|
84
|
+
this.uiConfig = config;
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
registerPlugin() {
|
|
88
|
+
const { staticRoute, staticPath, entryRoute, viewPath, uiConfig } = this;
|
|
89
|
+
if (!staticRoute || !staticPath) {
|
|
90
|
+
throw new Error(`Please call 'setStaticPath' before using 'registerPlugin'`);
|
|
91
|
+
}
|
|
92
|
+
else if (!entryRoute) {
|
|
93
|
+
throw new Error(`Please call 'setEntryRoute' before using 'registerPlugin'`);
|
|
94
|
+
}
|
|
95
|
+
else if (!viewPath) {
|
|
96
|
+
throw new Error(`Please call 'setViewsPath' before using 'registerPlugin'`);
|
|
97
|
+
}
|
|
98
|
+
else if (!uiConfig) {
|
|
99
|
+
throw new Error(`Please call 'setUIConfig' before using 'registerPlugin'`);
|
|
100
|
+
}
|
|
101
|
+
const app = new hono_1.Hono();
|
|
102
|
+
app.get(`${staticRoute}/*`, this.serveStatic({
|
|
103
|
+
root: node_path_1.default.relative(process.cwd(), staticPath),
|
|
104
|
+
rewriteRequestPath: (p) => p.replace(node_path_1.default.join(this.basePath, staticRoute), ''),
|
|
105
|
+
}));
|
|
106
|
+
app.route('/', this.apiRoutes);
|
|
107
|
+
const routeOrRoutes = entryRoute.route;
|
|
108
|
+
const routes = Array.isArray(routeOrRoutes) ? routeOrRoutes : [routeOrRoutes];
|
|
109
|
+
routes.forEach((route) => {
|
|
110
|
+
app[entryRoute.method](route, async (c) => {
|
|
111
|
+
const { name: fileName, params } = entryRoute.handler({
|
|
112
|
+
basePath: this.basePath,
|
|
113
|
+
uiConfig,
|
|
114
|
+
});
|
|
115
|
+
const template = await ejs_1.default.renderFile(`${this.viewPath}/${fileName}`, params);
|
|
116
|
+
return c.html(template);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
return app;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.HonoAdapter = HonoAdapter;
|
|
123
|
+
//# sourceMappingURL=HonoAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HonoAdapter.js","sourceRoot":"","sources":["../src/HonoAdapter.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA6B;AAW7B,8CAAsB;AACtB,+BAA4B;AAO5B,MAAa,WAAW;IAmBtB,YACY,WAKgB;QALhB,gBAAW,GAAX,WAAW,CAKK;QARlB,aAAQ,GAAG,GAAG,CAAC;QAUvB,IAAI,CAAC,SAAS,GAAG,IAAI,WAAI,EAAE,CAAC;IAC9B,CAAC;IAEM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KAAK,CAAC;QACvC,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;QAE9E,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YACvB,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,CAAU,EAAE,EAAE;gBACjD,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC;oBACpD,QAAQ,EAAE,IAAI,CAAC,QAAQ;oBACvB,QAAQ;iBACT,CAAC,CAAC;gBAEH,MAAM,QAAQ,GAAG,MAAM,aAAG,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,QAAQ,IAAI,QAAQ,EAAE,EAAE,MAAM,CAAC,CAAC;gBAC9E,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC1B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AArKD,kCAqKC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HonoAdapter } from './HonoAdapter';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HonoAdapter = void 0;
|
|
4
|
+
var HonoAdapter_1 = require("./HonoAdapter");
|
|
5
|
+
Object.defineProperty(exports, "HonoAdapter", { enumerable: true, get: function () { return HonoAdapter_1.HonoAdapter; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAAnC,0GAAA,WAAW,OAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bull-board/hono",
|
|
3
|
+
"version": "5.11.0",
|
|
4
|
+
"description": "A Hono server adapter for Bull-Board dashboard.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"bull",
|
|
7
|
+
"bullmq",
|
|
8
|
+
"redis",
|
|
9
|
+
"hono",
|
|
10
|
+
"adapter",
|
|
11
|
+
"queue",
|
|
12
|
+
"monitoring",
|
|
13
|
+
"dashboard"
|
|
14
|
+
],
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/felixmosh/bull-board.git",
|
|
18
|
+
"directory": "packages/hono"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "felixmosh",
|
|
22
|
+
"main": "dist/index.js",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc",
|
|
28
|
+
"clean": "rm -rf dist"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@bull-board/api": "5.11.0",
|
|
32
|
+
"@bull-board/ui": "5.11.0",
|
|
33
|
+
"ejs": "^3.1.7",
|
|
34
|
+
"hono": "^3.12.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@cloudflare/workers-types": "^4.20231218.0",
|
|
38
|
+
"@hono/node-server": "^1.4.0"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
}
|
|
43
|
+
}
|