fix: 埋点正则兼容/api前缀(originalUrl含前缀)
This commit is contained in:
+3
-3
@@ -68,12 +68,12 @@ app.use('/api/', limiter)
|
||||
|
||||
// 访问埋点:记录页面级 GET 请求(排除管理后台/认证/健康检查/高频轮询接口),小程序与 H5 访问均可统计
|
||||
// PV 口径:只记"页面首屏"接口(每打开一页只计1次),轮询/统计类接口不计——避免一次访问刷出6-8条
|
||||
const TRACKABLE_PAGES = [/^\/knowledge(\?|$)/, /^\/trend(\?|$)/, /^\/knowledge\/stats/, /^\/ai-chat\/quota/, /^\/user\/leaderboard/, /^\/feedback/]
|
||||
const TRACKABLE_PAGES = [/^\/?api\/knowledge(\?|$)/, /^\/?api\/trend(\?|$)/, /^\/?api\/knowledge\/stats/, /^\/?api\/ai-chat\/quota/, /^\/?api\/user\/leaderboard/, /^\/?api\/feedback/]
|
||||
app.use('/api', (req, res, next) => {
|
||||
try {
|
||||
if (req.method === 'GET' && !req.path.startsWith('/admin') && !req.path.startsWith('/auth')) {
|
||||
const path = String(req.originalUrl || req.path).split('?')[0]
|
||||
const isPage = TRACKABLE_PAGES.some((re) => re.test(path))
|
||||
const fullPath = String(req.originalUrl || req.path).split('?')[0]
|
||||
const isPage = TRACKABLE_PAGES.some((re) => re.test(fullPath)) || TRACKABLE_PAGES.some((re) => re.test(fullPath.replace(/^\/api/, '')))
|
||||
if (isPage) {
|
||||
const ua = String(req.headers['user-agent'] || '')
|
||||
const referer = String(req.headers.referer || '')
|
||||
|
||||
Reference in New Issue
Block a user