mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-05 00:45:19 +00:00
feat(admin): add opt-in server timing metrics
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
1 parent
7d239d62e8
commit
54d228dda5
43 files changed
+2014
-17
No files matched your search
@@ -0,0 +1,27 @@
|
||||
export const ADMIN_UI_REQUEST_HEADER = 'X-Admin-UI-Request'
|
||||
|
||||
function isAdminPath(path: string): boolean {
|
||||
return (
|
||||
path === '/admin' ||
|
||||
path.startsWith('/admin/') ||
|
||||
path === '/api/v1/admin' ||
|
||||
path.startsWith('/api/v1/admin/')
|
||||
)
|
||||
}
|
||||
|
||||
function requestPath(rawURL: string): string {
|
||||
const value = rawURL.trim()
|
||||
if (!value) return ''
|
||||
try {
|
||||
const origin = typeof window !== 'undefined' ? window.location.origin : 'http://localhost'
|
||||
return new URL(value, origin).pathname
|
||||
} catch {
|
||||
return value.split(/[?#]/, 1)[0]
|
||||
}
|
||||
}
|
||||
|
||||
export function shouldMarkAdminUIRequest(requestURL: string, pagePath?: string): boolean {
|
||||
const currentPath =
|
||||
pagePath ?? (typeof window !== 'undefined' ? window.location.pathname : '')
|
||||
return isAdminPath(requestPath(requestURL)) || isAdminPath(currentPath)
|
||||
}
|
||||
Reference in new issue
Block a user