@stravigor/devtools 0.4.2 → 0.4.3
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/package.json +1 -1
- package/src/devtools_provider.ts +22 -1
package/package.json
CHANGED
package/src/devtools_provider.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { ServiceProvider } from '@stravigor/core/core'
|
|
2
2
|
import type { Application } from '@stravigor/core/core'
|
|
3
|
+
import type Context from '@stravigor/core/http/context'
|
|
4
|
+
import Router from '@stravigor/core/http/router'
|
|
3
5
|
import DevtoolsManager from './devtools_manager.ts'
|
|
6
|
+
import { registerDashboard } from './dashboard/routes.ts'
|
|
4
7
|
|
|
5
8
|
export interface DevtoolsProviderOptions {
|
|
6
|
-
/**
|
|
9
|
+
/** Auto-create the devtools tables. Default: `true` */
|
|
7
10
|
ensureTables?: boolean
|
|
11
|
+
/** Auto-register the request-tracking middleware on the router. Default: `true` */
|
|
12
|
+
middleware?: boolean
|
|
13
|
+
/** Auto-register the dashboard routes at `/_devtools`. Default: `true` */
|
|
14
|
+
dashboard?: boolean
|
|
15
|
+
/** Custom auth guard for the dashboard. Receives the request context, returns boolean. */
|
|
16
|
+
guard?: (ctx: Context) => boolean | Promise<boolean>
|
|
8
17
|
}
|
|
9
18
|
|
|
10
19
|
export default class DevtoolsProvider extends ServiceProvider {
|
|
@@ -25,6 +34,18 @@ export default class DevtoolsProvider extends ServiceProvider {
|
|
|
25
34
|
if (this.options?.ensureTables !== false) {
|
|
26
35
|
await DevtoolsManager.ensureTables()
|
|
27
36
|
}
|
|
37
|
+
|
|
38
|
+
if (!DevtoolsManager.config.enabled) return
|
|
39
|
+
|
|
40
|
+
const router = app.resolve(Router)
|
|
41
|
+
|
|
42
|
+
if (this.options?.middleware !== false) {
|
|
43
|
+
router.use(DevtoolsManager.middleware())
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (this.options?.dashboard !== false) {
|
|
47
|
+
registerDashboard(router, this.options?.guard)
|
|
48
|
+
}
|
|
28
49
|
}
|
|
29
50
|
|
|
30
51
|
override shutdown(): void {
|