adonisjs-server-stats 1.5.3 → 1.5.4
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.
|
@@ -15,6 +15,13 @@ export default class ServerStatsProvider {
|
|
|
15
15
|
private debugController;
|
|
16
16
|
constructor(app: ApplicationService);
|
|
17
17
|
boot(): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Read start/kernel.ts and detect auth-related middleware in server.use()
|
|
20
|
+
* or router.use() blocks. Returns import paths of problematic middleware.
|
|
21
|
+
*
|
|
22
|
+
* Ignores initialize_auth_middleware (no DB query — just sets up ctx.auth).
|
|
23
|
+
*/
|
|
24
|
+
private detectGlobalAuthMiddleware;
|
|
18
25
|
ready(): Promise<void>;
|
|
19
26
|
private setupDevToolbar;
|
|
20
27
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server_stats_provider.d.ts","sourceRoot":"","sources":["../../../src/provider/server_stats_provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server_stats_provider.d.ts","sourceRoot":"","sources":["../../../src/provider/server_stats_provider.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAE9D,MAAM,CAAC,OAAO,OAAO,mBAAmB;IAc1B,SAAS,CAAC,GAAG,EAAE,kBAAkB;IAb7C,OAAO,CAAC,UAAU,CAA8C;IAChE,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,UAAU,CAA0B;IAC5C,OAAO,CAAC,cAAc,CAA8B;IACpD,OAAO,CAAC,mBAAmB,CAAmC;IAC9D,OAAO,CAAC,kBAAkB,CAAgC;IAC1D,OAAO,CAAC,uBAAuB,CAA8C;IAC7E,OAAO,CAAC,mBAAmB,CAA6C;IACxE,OAAO,CAAC,WAAW,CAAsB;IACzC,OAAO,CAAC,UAAU,CAA8C;IAChE,OAAO,CAAC,eAAe,CAAqC;IAC5D,OAAO,CAAC,eAAe,CAA+B;gBAEhC,GAAG,EAAE,kBAAkB;IAEvC,IAAI;IA4GV;;;;;OAKG;IACH,OAAO,CAAC,0BAA0B;IAmD5B,KAAK;YAuFG,eAAe;IAwF7B;;;;;;OAMG;YACW,cAAc;IAoGtB,QAAQ;CAwCf"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
1
2
|
import { registerDashboardRoutes } from '../dashboard/dashboard_routes.js';
|
|
2
3
|
import { DashboardStore } from '../dashboard/dashboard_store.js';
|
|
3
4
|
import { DebugStore } from '../debug/debug_store.js';
|
|
@@ -64,13 +65,33 @@ export default class ServerStatsProvider {
|
|
|
64
65
|
const dim = (s) => `\x1b[2m${s}\x1b[0m`;
|
|
65
66
|
const bold = (s) => `\x1b[1m${s}\x1b[0m`;
|
|
66
67
|
console.log(`\n${tag} routes registered:\n` +
|
|
67
|
-
registeredPaths.map((p) => ` ${dim('→')} ${bold(p)}`).join('\n')
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
registeredPaths.map((p) => ` ${dim('→')} ${bold(p)}`).join('\n'));
|
|
69
|
+
// Only warn about global auth middleware if:
|
|
70
|
+
// 1. shouldShow is NOT configured (user hasn't set up access control)
|
|
71
|
+
// 2. There IS auth middleware in server.use() or router.use()
|
|
72
|
+
if (!config.shouldShow) {
|
|
73
|
+
const authMiddleware = this.detectGlobalAuthMiddleware();
|
|
74
|
+
if (authMiddleware.length > 0) {
|
|
75
|
+
console.log(`\n${tag} ${bold('found global auth middleware that will run on every poll:')}\n` +
|
|
76
|
+
authMiddleware.map((m) => ` ${dim('→')} ${m}`).join('\n') +
|
|
77
|
+
'\n\n' +
|
|
78
|
+
` ${dim('these routes get polled every ~3s, so auth middleware will')}\n` +
|
|
79
|
+
` ${dim('trigger a DB query on each poll. here are two ways to fix it:')}\n` +
|
|
80
|
+
'\n' +
|
|
81
|
+
` ${bold('option 1:')} add a shouldShow callback to your config:\n` +
|
|
82
|
+
'\n' +
|
|
83
|
+
` ${dim('// config/server_stats.ts')}\n` +
|
|
84
|
+
` ${dim("shouldShow: (ctx) => ctx.auth?.user?.role === 'admin'")}\n` +
|
|
85
|
+
'\n' +
|
|
86
|
+
` ${bold('option 2:')} move auth middleware from router.use() to a route group:\n` +
|
|
87
|
+
'\n' +
|
|
88
|
+
` ${dim('// start/kernel.ts — remove from router.use()')}\n` +
|
|
89
|
+
` ${dim("// () => import('#middleware/silent_auth_middleware')")}\n` +
|
|
90
|
+
'\n' +
|
|
91
|
+
` ${dim('// start/routes.ts — add to your route groups instead')}\n` +
|
|
92
|
+
` ${dim("router.group(() => { ... }).use(middleware.silentAuth())")}\n`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
74
95
|
}
|
|
75
96
|
}
|
|
76
97
|
if (!this.app.usingEdgeJS)
|
|
@@ -84,6 +105,56 @@ export default class ServerStatsProvider {
|
|
|
84
105
|
// Edge not available — skip tag registration
|
|
85
106
|
}
|
|
86
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Read start/kernel.ts and detect auth-related middleware in server.use()
|
|
110
|
+
* or router.use() blocks. Returns import paths of problematic middleware.
|
|
111
|
+
*
|
|
112
|
+
* Ignores initialize_auth_middleware (no DB query — just sets up ctx.auth).
|
|
113
|
+
*/
|
|
114
|
+
detectGlobalAuthMiddleware() {
|
|
115
|
+
const found = [];
|
|
116
|
+
try {
|
|
117
|
+
// Try both .ts and .js extensions
|
|
118
|
+
let source = '';
|
|
119
|
+
for (const ext of ['ts', 'js']) {
|
|
120
|
+
try {
|
|
121
|
+
source = readFileSync(this.app.makePath('start', `kernel.${ext}`), 'utf-8');
|
|
122
|
+
if (source)
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// Try next extension
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (!source)
|
|
130
|
+
return found;
|
|
131
|
+
// Extract server.use([...]) and router.use([...]) blocks
|
|
132
|
+
const useBlockRegex = /(?:server|router)\.use\(\s*\[([\s\S]*?)\]\s*\)/g;
|
|
133
|
+
let match;
|
|
134
|
+
while ((match = useBlockRegex.exec(source)) !== null) {
|
|
135
|
+
const block = match[1];
|
|
136
|
+
// Find all import paths in this block
|
|
137
|
+
const importRegex = /import\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
138
|
+
let importMatch;
|
|
139
|
+
while ((importMatch = importRegex.exec(block)) !== null) {
|
|
140
|
+
const importPath = importMatch[1];
|
|
141
|
+
// Skip initialize_auth_middleware — it just sets up ctx.auth, no DB query
|
|
142
|
+
if (importPath.includes('initialize_auth'))
|
|
143
|
+
continue;
|
|
144
|
+
// Detect auth-related middleware
|
|
145
|
+
if (importPath.includes('auth') ||
|
|
146
|
+
importPath.includes('silent_auth') ||
|
|
147
|
+
importPath.includes('silentAuth')) {
|
|
148
|
+
found.push(importPath);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// Can't read kernel file — skip detection
|
|
155
|
+
}
|
|
156
|
+
return found;
|
|
157
|
+
}
|
|
87
158
|
async ready() {
|
|
88
159
|
const config = this.app.config.get('server_stats');
|
|
89
160
|
if (!config)
|