isr-engine 2.6.21 → 3.0.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 +93 -620
- package/dist/{abVariantContext-Cqp-uxtd.cjs → abVariantContext-BcnxBn4V.cjs} +17 -257
- package/dist/abVariantContext-BcnxBn4V.cjs.map +1 -0
- package/dist/{abVariantContext-CWCdRSdG.js → abVariantContext-BmZZi1YZ.js} +12 -205
- package/dist/abVariantContext-BmZZi1YZ.js.map +1 -0
- package/dist/app/createISRApp.d.ts +2 -2
- package/dist/cli/cli.cjs +1 -1
- package/dist/cli/cli.js +1 -1
- package/dist/cli/start.d.ts +1 -1
- package/dist/config/loadConfig.d.ts +1 -1
- package/dist/config/normalizeEngineConfig.d.ts +1 -1
- package/dist/config/resolveRuntimeRedis.d.ts +1 -1
- package/dist/{createCacheInspectorMiddleware-DYJ2WGYu.js → createCacheInspectorMiddleware-BY6MX88X.js} +2 -2
- package/dist/{createCacheInspectorMiddleware-DYJ2WGYu.js.map → createCacheInspectorMiddleware-BY6MX88X.js.map} +1 -1
- package/dist/{createCacheInspectorMiddleware-Byzz8ZlU.cjs → createCacheInspectorMiddleware-DZr98Zfn.cjs} +2 -2
- package/dist/{createCacheInspectorMiddleware-Byzz8ZlU.cjs.map → createCacheInspectorMiddleware-DZr98Zfn.cjs.map} +1 -1
- package/dist/{createISRApp-C9Bezuit.cjs → createISRApp-CHiiWF3P.cjs} +272 -44
- package/dist/createISRApp-CHiiWF3P.cjs.map +1 -0
- package/dist/{createISRApp-CylUYiIU.js → createISRApp-CS6XfjHl.js} +238 -40
- package/dist/createISRApp-CS6XfjHl.js.map +1 -0
- package/dist/{createImagePlugin-birVNynL.cjs → createImagePlugin-BtJzr0t-.cjs} +2 -2
- package/dist/{createImagePlugin-birVNynL.cjs.map → createImagePlugin-BtJzr0t-.cjs.map} +1 -1
- package/dist/{createImagePlugin-_ntL0DcT.js → createImagePlugin-Ddo5t3dJ.js} +2 -2
- package/dist/{createImagePlugin-_ntL0DcT.js.map → createImagePlugin-Ddo5t3dJ.js.map} +1 -1
- package/dist/defaults/runtime/browserObservability.d.ts.map +1 -1
- package/dist/defaults/runtime/dev-style-resource-dispatcher.server.d.ts.map +1 -1
- package/dist/engine/ISREngine.d.ts +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/isr/ISRRoutes.d.ts +3 -3
- package/dist/isr-engine.cjs +47 -27
- package/dist/isr-engine.cjs.map +1 -1
- package/dist/isr-engine.js +42 -22
- package/dist/isr-engine.js.map +1 -1
- package/dist/metrics/PromMetrics.d.ts.map +1 -1
- package/dist/plugin/createDevCssHandoffPlugin.d.ts.map +1 -1
- package/dist/plugin/createIsrPlugin.d.ts.map +1 -1
- package/dist/rsc/index.cjs +2 -2
- package/dist/rsc/index.js +2 -2
- package/dist/rsc/revalidate.d.ts.map +1 -1
- package/dist/rsc/revalidationMetrics.d.ts +6 -0
- package/dist/rsc/revalidationMetrics.d.ts.map +1 -0
- package/dist/{rsc-lvWPTuVD.js → rsc-BSxvkPHd.js} +2 -2
- package/dist/{rsc-lvWPTuVD.js.map → rsc-BSxvkPHd.js.map} +1 -1
- package/dist/{rsc-H7D_meHu.cjs → rsc-NB-Uka7j.cjs} +2 -2
- package/dist/{rsc-H7D_meHu.cjs.map → rsc-NB-Uka7j.cjs.map} +1 -1
- package/dist/server/manager.d.ts +1 -1
- package/dist/server/opsConfig.d.ts +1 -1
- package/dist/server/productionRuntime.d.ts +2 -2
- package/dist/server/productionRuntime.d.ts.map +1 -1
- package/dist/server/types.d.ts +1 -1
- package/dist/ssg/spider.d.ts.map +1 -1
- package/dist/types/ISRConfig.d.ts.map +1 -1
- package/dist/utils/resolveFetchHandler.d.ts.map +1 -1
- package/package.json +28 -32
- package/src/defaults/runtime/browserObservability.ts +2 -4
- package/src/defaults/runtime/dev-style-resource-dispatcher.server.ts +2 -3
- package/src/types/ISRConfig.ts +2 -7
- package/src/utils/resolveFetchHandler.ts +1 -3
- package/dist/abVariantContext-CWCdRSdG.js.map +0 -1
- package/dist/abVariantContext-Cqp-uxtd.cjs.map +0 -1
- package/dist/createISRApp-C9Bezuit.cjs.map +0 -1
- package/dist/createISRApp-CylUYiIU.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
2
|
import { c as requestContext, i as getRequestContext } from "./RequestContext-BVQ-rOmV.js";
|
|
3
|
-
import { a as isUncacheable,
|
|
3
|
+
import { a as isUncacheable, f as setRevalidationMetricRecorder, l as registerInvalidator, p as Logger, r as collectTags, s as runWithTagStore } from "./abVariantContext-BmZZi1YZ.js";
|
|
4
4
|
import { a as withLocale, c as parseCookieHeader, i as resolveI18nConfig, l as readCookie, n as negotiateLocale } from "./i18n-Dobe0Wxn.js";
|
|
5
5
|
import fs, { createReadStream } from "node:fs";
|
|
6
6
|
import path from "node:path";
|
|
@@ -22,6 +22,7 @@ import { Readable } from "node:stream";
|
|
|
22
22
|
import os from "node:os";
|
|
23
23
|
import http from "node:http";
|
|
24
24
|
import { LRUCache } from "lru-cache";
|
|
25
|
+
import { Counter, Gauge, Histogram, Registry, collectDefaultMetrics } from "prom-client";
|
|
25
26
|
import { pathToFileURL as pathToFileURL$1 } from "url";
|
|
26
27
|
import { createHash as createHash$1, randomUUID as randomUUID$1 } from "crypto";
|
|
27
28
|
import * as esbuild from "esbuild";
|
|
@@ -1326,7 +1327,7 @@ function resolveFetchHandler(module) {
|
|
|
1326
1327
|
}
|
|
1327
1328
|
var package_default = {
|
|
1328
1329
|
name: "isr-engine",
|
|
1329
|
-
version: "
|
|
1330
|
+
version: "3.0.0",
|
|
1330
1331
|
description: "ISR/SSG/Fallback rendering orchestration on Vite + React 19 RSC.",
|
|
1331
1332
|
license: "UNLICENSED",
|
|
1332
1333
|
repository: {
|
|
@@ -1430,11 +1431,11 @@ var package_default = {
|
|
|
1430
1431
|
"test:workers": "tsc --noEmit -p scripts/fixtures/tsconfig.json && node scripts/check-workers-runtime.mjs",
|
|
1431
1432
|
"test:release": "node scripts/check-release.mjs"
|
|
1432
1433
|
},
|
|
1433
|
-
engines: { "node": "
|
|
1434
|
+
engines: { "node": "24.15.0" },
|
|
1434
1435
|
packageManager: "pnpm@9.15.9",
|
|
1435
1436
|
dependencies: {
|
|
1436
|
-
"@vitejs/plugin-rsc": "0.5.
|
|
1437
|
-
"chalk": "^
|
|
1437
|
+
"@vitejs/plugin-rsc": "0.5.39",
|
|
1438
|
+
"chalk": "^6.0.1",
|
|
1438
1439
|
"commander": "^12.1.0",
|
|
1439
1440
|
"compression": "^1.8.2",
|
|
1440
1441
|
"css-tree": "^3.2.1",
|
|
@@ -1443,24 +1444,23 @@ var package_default = {
|
|
|
1443
1444
|
"helmet": "^7.1.0",
|
|
1444
1445
|
"ipaddr.js": "^2.5.0",
|
|
1445
1446
|
"lru-cache": "^10.4.3",
|
|
1446
|
-
"ora": "^
|
|
1447
|
+
"ora": "^10.0.0",
|
|
1447
1448
|
"parse5": "^8.0.1",
|
|
1448
1449
|
"prom-client": "^15.1.3",
|
|
1450
|
+
"rsc-html-stream": "0.0.7",
|
|
1449
1451
|
"sharp": "^0.35.5",
|
|
1450
|
-
"sitemap": "^
|
|
1451
|
-
"typescript": "^
|
|
1452
|
+
"sitemap": "^10.0.0",
|
|
1453
|
+
"typescript": "^6.0.3"
|
|
1452
1454
|
},
|
|
1453
1455
|
peerDependencies: {
|
|
1454
|
-
"react": "19.3.
|
|
1455
|
-
"react-dom": "19.3.
|
|
1456
|
-
"react-server-dom-webpack": "19.3.0-canary-bd6ea412-20260824",
|
|
1457
|
-
"rsc-html-stream": "^0.0.7",
|
|
1456
|
+
"react": "19.3.1",
|
|
1457
|
+
"react-dom": "19.3.1",
|
|
1458
1458
|
"vite": "8.1.6"
|
|
1459
1459
|
},
|
|
1460
|
-
optionalDependencies: { "ioredis": "^5.
|
|
1460
|
+
optionalDependencies: { "ioredis": "^5.11.1" },
|
|
1461
1461
|
devDependencies: {
|
|
1462
|
-
"@eslint/js": "^9.
|
|
1463
|
-
"@playwright/test": "
|
|
1462
|
+
"@eslint/js": "^9.39.5",
|
|
1463
|
+
"@playwright/test": "1.65.1",
|
|
1464
1464
|
"@semantic-release/commit-analyzer": "13.0.1",
|
|
1465
1465
|
"@semantic-release/exec": "7.1.0",
|
|
1466
1466
|
"@semantic-release/npm": "13.2.0",
|
|
@@ -1468,34 +1468,31 @@ var package_default = {
|
|
|
1468
1468
|
"@types/compression": "^1.7.5",
|
|
1469
1469
|
"@types/css-tree": "^3.2.0",
|
|
1470
1470
|
"@types/express": "^5.0.0",
|
|
1471
|
-
"@types/ioredis-mock": "^8.2.
|
|
1472
|
-
"@types/node": "
|
|
1471
|
+
"@types/ioredis-mock": "^8.2.8",
|
|
1472
|
+
"@types/node": "24.19.2",
|
|
1473
1473
|
"@types/react": "^19.2.15",
|
|
1474
1474
|
"@types/react-dom": "^19.0.0",
|
|
1475
|
-
"@typescript-eslint/eslint-plugin": "
|
|
1476
|
-
"@typescript-eslint/parser": "
|
|
1475
|
+
"@typescript-eslint/eslint-plugin": "8.72.2",
|
|
1476
|
+
"@typescript-eslint/parser": "8.72.2",
|
|
1477
1477
|
"@vitest/coverage-v8": "^4.1.12",
|
|
1478
|
-
"autocannon": "^8.0.0",
|
|
1479
1478
|
"eslint": "^9.15.0",
|
|
1480
|
-
"eslint-config-prettier": "^
|
|
1481
|
-
"eslint-plugin-prettier": "^5.5.
|
|
1479
|
+
"eslint-config-prettier": "^10.1.8",
|
|
1480
|
+
"eslint-plugin-prettier": "^5.5.7",
|
|
1482
1481
|
"eslint-plugin-react": "^7.37.2",
|
|
1483
|
-
"eslint-plugin-react-hooks": "^
|
|
1482
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
1484
1483
|
"globals": "^15.9.0",
|
|
1485
1484
|
"happy-dom": "^21.0.4",
|
|
1486
1485
|
"husky": "^9.1.7",
|
|
1487
1486
|
"ioredis-mock": "^8.9.0",
|
|
1488
|
-
"jsdom": "^29.1.1",
|
|
1489
1487
|
"miniflare": "4.20260730.0",
|
|
1490
|
-
"prettier": "^3.
|
|
1491
|
-
"react": "19.3.
|
|
1492
|
-
"react-dom": "19.3.
|
|
1493
|
-
"react-server-dom-webpack": "19.3.0-canary-bd6ea412-20260824",
|
|
1488
|
+
"prettier": "^3.10.1",
|
|
1489
|
+
"react": "19.3.1",
|
|
1490
|
+
"react-dom": "19.3.1",
|
|
1494
1491
|
"rimraf": "^6.1.4",
|
|
1495
|
-
"
|
|
1496
|
-
"
|
|
1497
|
-
"
|
|
1498
|
-
"
|
|
1492
|
+
"sass-embedded": "^1.108.2",
|
|
1493
|
+
"semantic-release": "25.0.9",
|
|
1494
|
+
"tsc-alias": "^1.9.10",
|
|
1495
|
+
"undici": "8.12.4",
|
|
1499
1496
|
"vite": "8.1.6",
|
|
1500
1497
|
"vitest": "^4.1.12"
|
|
1501
1498
|
},
|
|
@@ -1511,7 +1508,7 @@ var package_default = {
|
|
|
1511
1508
|
"undici@7": "7.30.2",
|
|
1512
1509
|
"js-yaml@4": "4.3.2",
|
|
1513
1510
|
"form-data@4": "4.0.6",
|
|
1514
|
-
"@typescript-eslint/typescript-estree
|
|
1511
|
+
"@typescript-eslint/typescript-estree>minimatch": "11.0.5"
|
|
1515
1512
|
} }
|
|
1516
1513
|
};
|
|
1517
1514
|
//#endregion
|
|
@@ -2318,6 +2315,207 @@ function createHybridCacheStore(opts) {
|
|
|
2318
2315
|
};
|
|
2319
2316
|
}
|
|
2320
2317
|
//#endregion
|
|
2318
|
+
//#region src/metrics/PromMetrics.ts
|
|
2319
|
+
/**
|
|
2320
|
+
* PromMetrics —— prom-client 包装,导出 Prometheus 文本格式
|
|
2321
|
+
*
|
|
2322
|
+
* 设计:
|
|
2323
|
+
* - prom-client 是 Node 生态的事实标准(Grafana / Datadog / Prometheus 直接抓取)
|
|
2324
|
+
* - 单 Registry,避免污染全局;用户业务可拿 `promRegistry` 自行注册自家 metric
|
|
2325
|
+
* - 响应时间用 Histogram(带桶),不是平均值 —— 才能正确算 P95/P99
|
|
2326
|
+
* - 默认采集 process_*(CPU / RSS / event-loop lag)—— 一行 collectDefaultMetrics
|
|
2327
|
+
*/
|
|
2328
|
+
var PromMetrics_exports = /* @__PURE__ */ __exportAll({
|
|
2329
|
+
cacheEntriesGauge: () => cacheEntriesGauge,
|
|
2330
|
+
cacheHitsTotal: () => cacheHitsTotal,
|
|
2331
|
+
cacheRevalidatingGauge: () => cacheRevalidatingGauge,
|
|
2332
|
+
createPrometheusMetricsMiddleware: () => createPrometheusMetricsMiddleware,
|
|
2333
|
+
httpRequestDurationSeconds: () => httpRequestDurationSeconds,
|
|
2334
|
+
httpRequestsTotal: () => httpRequestsTotal,
|
|
2335
|
+
invalidatorFailuresTotal: () => invalidatorFailuresTotal,
|
|
2336
|
+
invalidatorRunsTotal: () => invalidatorRunsTotal,
|
|
2337
|
+
l2ReadTimeoutsTotal: () => l2ReadTimeoutsTotal,
|
|
2338
|
+
normalizeRoute: () => normalizeRoute,
|
|
2339
|
+
promRegistry: () => promRegistry,
|
|
2340
|
+
recordHttpRequest: () => recordHttpRequest
|
|
2341
|
+
});
|
|
2342
|
+
var promRegistry = new Registry();
|
|
2343
|
+
collectDefaultMetrics({
|
|
2344
|
+
register: promRegistry,
|
|
2345
|
+
prefix: "isr_"
|
|
2346
|
+
});
|
|
2347
|
+
var httpRequestsTotal = new Counter({
|
|
2348
|
+
name: "isr_http_requests_total",
|
|
2349
|
+
help: "Total ISR HTTP requests",
|
|
2350
|
+
labelNames: [
|
|
2351
|
+
"method",
|
|
2352
|
+
"route",
|
|
2353
|
+
"status",
|
|
2354
|
+
"mode",
|
|
2355
|
+
"cache"
|
|
2356
|
+
],
|
|
2357
|
+
registers: [promRegistry]
|
|
2358
|
+
});
|
|
2359
|
+
var httpRequestDurationSeconds = new Histogram({
|
|
2360
|
+
name: "isr_http_request_duration_seconds",
|
|
2361
|
+
help: "ISR HTTP request duration",
|
|
2362
|
+
labelNames: [
|
|
2363
|
+
"method",
|
|
2364
|
+
"route",
|
|
2365
|
+
"mode",
|
|
2366
|
+
"cache"
|
|
2367
|
+
],
|
|
2368
|
+
buckets: [
|
|
2369
|
+
.001,
|
|
2370
|
+
.005,
|
|
2371
|
+
.01,
|
|
2372
|
+
.025,
|
|
2373
|
+
.05,
|
|
2374
|
+
.1,
|
|
2375
|
+
.25,
|
|
2376
|
+
.5,
|
|
2377
|
+
1,
|
|
2378
|
+
2.5,
|
|
2379
|
+
5
|
|
2380
|
+
],
|
|
2381
|
+
registers: [promRegistry]
|
|
2382
|
+
});
|
|
2383
|
+
var cacheEntriesGauge = new Gauge({
|
|
2384
|
+
name: "isr_cache_entries",
|
|
2385
|
+
help: "Current ISR cache entries (L1 LRU size)",
|
|
2386
|
+
labelNames: ["backend"],
|
|
2387
|
+
registers: [promRegistry]
|
|
2388
|
+
});
|
|
2389
|
+
var cacheRevalidatingGauge = new Gauge({
|
|
2390
|
+
name: "isr_cache_revalidating_inflight",
|
|
2391
|
+
help: "Number of in-flight background revalidations",
|
|
2392
|
+
registers: [promRegistry]
|
|
2393
|
+
});
|
|
2394
|
+
var cacheHitsTotal = new Counter({
|
|
2395
|
+
name: "isr_cache_hits_total",
|
|
2396
|
+
help: "ISR cache hits",
|
|
2397
|
+
labelNames: ["status"],
|
|
2398
|
+
registers: [promRegistry]
|
|
2399
|
+
});
|
|
2400
|
+
var invalidatorRunsTotal = new Counter({
|
|
2401
|
+
name: "isr_invalidator_runs_total",
|
|
2402
|
+
help: "Total revalidate dispatches (one increment per revalidatePath/Tag call with ≥1 invalidator)",
|
|
2403
|
+
labelNames: ["kind", "target"],
|
|
2404
|
+
registers: [promRegistry]
|
|
2405
|
+
});
|
|
2406
|
+
var invalidatorFailuresTotal = new Counter({
|
|
2407
|
+
name: "isr_invalidator_failures_total",
|
|
2408
|
+
help: "Per-invalidator failures during revalidate dispatch (one increment per failing invalidator)",
|
|
2409
|
+
labelNames: ["kind", "target"],
|
|
2410
|
+
registers: [promRegistry]
|
|
2411
|
+
});
|
|
2412
|
+
var l2ReadTimeoutsTotal = new Counter({
|
|
2413
|
+
name: "isr_l2_read_timeouts_total",
|
|
2414
|
+
help: "L2 cache async read timeouts (raceWithTimeout fired before underlying promise resolved)",
|
|
2415
|
+
registers: [promRegistry]
|
|
2416
|
+
});
|
|
2417
|
+
/**
|
|
2418
|
+
* 路由归一化 —— 防 Prometheus label 基数爆炸。
|
|
2419
|
+
*
|
|
2420
|
+
* 动态段(id / uuid / hex / 长 hash)直接作为 label 值会让时间序列数爆炸
|
|
2421
|
+
* (每个 /books/123 都是新序列),Prometheus 存储成本线性暴涨、查询变慢。
|
|
2422
|
+
*
|
|
2423
|
+
* 规则:
|
|
2424
|
+
* - 纯数字段(1 ~ 20 位) → `:id`
|
|
2425
|
+
* - UUID v1-v5 → `:uuid`
|
|
2426
|
+
* - 长 hex(≥16 字符全 hex)→ `:hash`
|
|
2427
|
+
* - base64url/大小写混合长串(≥24 字符,含数字和字母)→ `:hash`
|
|
2428
|
+
*
|
|
2429
|
+
* 命中任意规则即替换;其他保留原样(`/books` `/about` 保留)。
|
|
2430
|
+
*
|
|
2431
|
+
* 可用 `addRouteNormalizeRule(pattern, replacement)` 扩展业务特有规则。
|
|
2432
|
+
*/
|
|
2433
|
+
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
2434
|
+
var LONG_HEX_RE = /^[0-9a-f]{16,}$/i;
|
|
2435
|
+
var OPAQUE_ID_RE = /^[A-Za-z0-9_-]{24,}$/;
|
|
2436
|
+
var PURE_DIGIT_RE = /^\d{1,20}$/;
|
|
2437
|
+
var customRules = [];
|
|
2438
|
+
function normalizeRoute(route) {
|
|
2439
|
+
if (!route || route === "/") return "/";
|
|
2440
|
+
const segments = route.split("/");
|
|
2441
|
+
for (let i = 0; i < segments.length; i++) {
|
|
2442
|
+
const seg = segments[i];
|
|
2443
|
+
if (!seg) continue;
|
|
2444
|
+
let replaced = null;
|
|
2445
|
+
for (const rule of customRules) {
|
|
2446
|
+
replaced = rule(seg);
|
|
2447
|
+
if (replaced) break;
|
|
2448
|
+
}
|
|
2449
|
+
if (replaced) {
|
|
2450
|
+
segments[i] = replaced;
|
|
2451
|
+
continue;
|
|
2452
|
+
}
|
|
2453
|
+
if (PURE_DIGIT_RE.test(seg)) segments[i] = ":id";
|
|
2454
|
+
else if (UUID_RE.test(seg)) segments[i] = ":uuid";
|
|
2455
|
+
else if (LONG_HEX_RE.test(seg)) segments[i] = ":hash";
|
|
2456
|
+
else if (OPAQUE_ID_RE.test(seg)) segments[i] = ":hash";
|
|
2457
|
+
}
|
|
2458
|
+
return segments.join("/");
|
|
2459
|
+
}
|
|
2460
|
+
setRevalidationMetricRecorder((event, kind, target) => {
|
|
2461
|
+
(event === "run" ? invalidatorRunsTotal : invalidatorFailuresTotal).inc({
|
|
2462
|
+
kind,
|
|
2463
|
+
target: kind === "path" ? normalizeRoute(target) : target
|
|
2464
|
+
});
|
|
2465
|
+
});
|
|
2466
|
+
/** 一行调用更新所有计数 —— 给 isrCacheMiddleware / 中间件用 */
|
|
2467
|
+
function recordHttpRequest(opts) {
|
|
2468
|
+
const route = normalizeRoute(opts.route);
|
|
2469
|
+
httpRequestsTotal.inc({
|
|
2470
|
+
method: opts.method,
|
|
2471
|
+
route,
|
|
2472
|
+
status: String(opts.status),
|
|
2473
|
+
mode: opts.mode,
|
|
2474
|
+
cache: opts.cache
|
|
2475
|
+
});
|
|
2476
|
+
httpRequestDurationSeconds.observe({
|
|
2477
|
+
method: opts.method,
|
|
2478
|
+
route,
|
|
2479
|
+
mode: opts.mode,
|
|
2480
|
+
cache: opts.cache
|
|
2481
|
+
}, opts.durationMs / 1e3);
|
|
2482
|
+
if (opts.cache) cacheHitsTotal.inc({ status: opts.cache });
|
|
2483
|
+
}
|
|
2484
|
+
/**
|
|
2485
|
+
* Express / connect 中间件:暴露 /metrics 端点(Prometheus text exposition format)
|
|
2486
|
+
*
|
|
2487
|
+
* 认证:可选 Bearer token —— 未设 token 时保持旧行为(匿名可访问)。
|
|
2488
|
+
* 生产建议:`createPrometheusMetricsMiddleware({ token: process.env.METRICS_TOKEN })`。
|
|
2489
|
+
*/
|
|
2490
|
+
function createPrometheusMetricsMiddleware(pathOrOptions = {}) {
|
|
2491
|
+
const options = typeof pathOrOptions === "string" ? { path: pathOrOptions } : pathOrOptions;
|
|
2492
|
+
const path = options.path ?? "/metrics";
|
|
2493
|
+
const token = options.token && options.token !== "" ? options.token : null;
|
|
2494
|
+
const unauthorizedStatus = options.unauthorizedStatus ?? 401;
|
|
2495
|
+
return async function(req, res, next) {
|
|
2496
|
+
if (req.url !== path || req.method !== "GET") return next();
|
|
2497
|
+
if (token) {
|
|
2498
|
+
const authHeader = req.headers?.["authorization"];
|
|
2499
|
+
const raw = Array.isArray(authHeader) ? authHeader[0] : authHeader;
|
|
2500
|
+
if (!(typeof raw === "string" && raw === `Bearer ${token}`)) {
|
|
2501
|
+
res.statusCode = unauthorizedStatus;
|
|
2502
|
+
res.setHeader("WWW-Authenticate", "Bearer realm=\"metrics\"");
|
|
2503
|
+
res.end("Unauthorized");
|
|
2504
|
+
return;
|
|
2505
|
+
}
|
|
2506
|
+
}
|
|
2507
|
+
try {
|
|
2508
|
+
const body = await promRegistry.metrics();
|
|
2509
|
+
res.setHeader("content-type", promRegistry.contentType);
|
|
2510
|
+
res.statusCode = 200;
|
|
2511
|
+
res.end(body);
|
|
2512
|
+
} catch (err) {
|
|
2513
|
+
res.statusCode = 500;
|
|
2514
|
+
res.end(`metrics error: ${err instanceof Error ? err.message : String(err)}`);
|
|
2515
|
+
}
|
|
2516
|
+
};
|
|
2517
|
+
}
|
|
2518
|
+
//#endregion
|
|
2321
2519
|
//#region src/config/loadConfig.ts
|
|
2322
2520
|
/**
|
|
2323
2521
|
* 配置加载工具
|
|
@@ -4405,13 +4603,13 @@ function createIsrCacheMiddleware(explicitConfig, options = {}) {
|
|
|
4405
4603
|
development: true
|
|
4406
4604
|
}));
|
|
4407
4605
|
try {
|
|
4408
|
-
const inspector = opsConfig.inventory.enabled ? (await import("./createCacheInspectorMiddleware-
|
|
4606
|
+
const inspector = opsConfig.inventory.enabled ? (await import("./createCacheInspectorMiddleware-BY6MX88X.js")).createCacheInspectorMiddleware(nextHandler, opsConfig) : void 0;
|
|
4409
4607
|
handler = nextHandler;
|
|
4410
4608
|
server.middlewares.use((req, res, next) => {
|
|
4411
4609
|
if (handler !== nextHandler) return next();
|
|
4412
4610
|
if (opsConfig.metrics.enabled && req.url === "/metrics" && req.method === "GET") {
|
|
4413
4611
|
createOpsAuthMiddleware("metrics", opsConfig)(req, res, () => {
|
|
4414
|
-
|
|
4612
|
+
Promise.resolve().then(() => PromMetrics_exports).then(async ({ promRegistry }) => {
|
|
4415
4613
|
const body = await promRegistry.metrics();
|
|
4416
4614
|
res.setHeader("content-type", promRegistry.contentType);
|
|
4417
4615
|
res.end(body);
|
|
@@ -5584,7 +5782,7 @@ async function createProductionRuntime(config, options = {}) {
|
|
|
5584
5782
|
app.use("/assets", (_req, res) => {
|
|
5585
5783
|
res.status(404).set("Cache-Control", "no-store").end();
|
|
5586
5784
|
});
|
|
5587
|
-
const { createImageMiddleware } = await import("./createImagePlugin-
|
|
5785
|
+
const { createImageMiddleware } = await import("./createImagePlugin-Ddo5t3dJ.js").then((n) => n.r);
|
|
5588
5786
|
const { resolveImageOptions } = await Promise.resolve().then(() => resolveImageOptions_exports);
|
|
5589
5787
|
app.use(createImageMiddleware(resolveImageOptions(config.runtime.images), {}, clientDir));
|
|
5590
5788
|
const { createAutoCacheStore } = await Promise.resolve().then(() => createAutoCacheStore_exports);
|
|
@@ -5656,7 +5854,7 @@ async function createProductionRuntime(config, options = {}) {
|
|
|
5656
5854
|
});
|
|
5657
5855
|
cleanups.push(() => cache.destroy());
|
|
5658
5856
|
if (opsConfig.inventory.enabled) {
|
|
5659
|
-
const { createCacheInspectorMiddleware } = await import("./createCacheInspectorMiddleware-
|
|
5857
|
+
const { createCacheInspectorMiddleware } = await import("./createCacheInspectorMiddleware-BY6MX88X.js");
|
|
5660
5858
|
app.use(createCacheInspectorMiddleware(cache, opsConfig));
|
|
5661
5859
|
logger$8.info("🔍 ISR cache inventory 已启用:GET /__isr/cache/inventory");
|
|
5662
5860
|
}
|
|
@@ -5681,7 +5879,7 @@ async function createProductionRuntime(config, options = {}) {
|
|
|
5681
5879
|
if (res.getHeader("X-Resolved-Mode") === "ssg" || ssgAliases.has(decodeHtmlPathname(req.path)) && explicitRoutes.has(decodeHtmlPathname(req.path))) return next();
|
|
5682
5880
|
staticHtml(req, res, next);
|
|
5683
5881
|
});
|
|
5684
|
-
const { promRegistry } = await
|
|
5882
|
+
const { promRegistry } = await Promise.resolve().then(() => PromMetrics_exports);
|
|
5685
5883
|
if (opsConfig.metrics.enabled) app.get("/metrics", createOpsAuthMiddleware("metrics", opsConfig), async (_req, res) => {
|
|
5686
5884
|
try {
|
|
5687
5885
|
res.set("content-type", promRegistry.contentType);
|
|
@@ -7317,6 +7515,6 @@ async function createISRApp(appOption) {
|
|
|
7317
7515
|
};
|
|
7318
7516
|
}
|
|
7319
7517
|
//#endregion
|
|
7320
|
-
export {
|
|
7518
|
+
export { isTestFile as $, createMemoryCacheStore as A, logger$8 as B, loadConfig as C, promRegistry as D, invalidatorRunsTotal as E, FallbackChain as F, scanComponents as G, package_default as H, InternalStrategies as I, parseComponentFromFile as J, scanProject as K, RenderModes as L, getRouteFallbackChain as M, matchRoutePattern as N, recordHttpRequest as O, resolveRenderMode as P, isCodeFile as Q, extractSsgRoutes as R, createOpsAuthMiddleware as S, invalidatorFailuresTotal as T, resolveFetchHandler as U, DEFAULT_PORT as V, DEFAULT_SCAN_CONFIG as W, parseRouteFromFile as X, parseComponents as Y, parseRoutes as Z, RedisInvalidationBus as _, DEFAULT_SEO_CONFIG as a, assertDistinctHtmlRouteIdentities as at, createCoherentCacheStore as b, startAppServer as c, startServer as d, readDirRecursive as et, createProductionRuntime as f, createIsrCacheMiddleware as g, createIsrCacheHandler as h, createSEOEngine as i, CacheCleanup as it, getFallbackChain as j, createHybridCacheStore as k, createABVariantMiddleware as l, generateStaticCspManifest as m, ISREngine as n, isProd as nt, mergeSEOConfig as o, resolveImageOptions as ot, prepareProductionBuild as p, scanRoutes as q, SEOEngine as r, getEnv as rt, shutdownServer as s, createISRApp as t, isDev as tt, closeServer as u, RedisCacheAdapter as v, createPrometheusMetricsMiddleware as w, createDevAssetRequestMiddleware as x, MemoryCacheAdapter as y, spiderSsgRoutes as z };
|
|
7321
7519
|
|
|
7322
|
-
//# sourceMappingURL=createISRApp-
|
|
7520
|
+
//# sourceMappingURL=createISRApp-CS6XfjHl.js.map
|