Reduce scan terminal origin load

This commit is contained in:
2569718930@qq.com
2026-05-30 21:55:45 +08:00
parent 9c239c0394
commit 74a2d71644
3 changed files with 42 additions and 3 deletions
@@ -25,6 +25,37 @@ export function runTests() {
const scanForced = buildForceRefreshProxyCachePolicy("true", 10);
assert.equal(scanForced.fetchMode, "no-store");
const scanTerminalProxySource = fs.readFileSync(
path.join(process.cwd(), "app", "api", "scan", "terminal", "route.ts"),
"utf8",
);
assert.match(
scanTerminalProxySource,
/DASHBOARD_REFRESH_POLICY_SEC\.scanRows/,
"scan terminal proxy cache TTL should match the dashboard scan refresh cadence instead of a short literal TTL",
);
assert.doesNotMatch(
scanTerminalProxySource,
/buildForceRefreshProxyCachePolicy\(forceRefresh,\s*10\)/,
"scan terminal proxy must not use the old 10 second edge cache because it over-drives the slow scan endpoint",
);
const scanTerminalClientSource = fs.readFileSync(
path.join(
process.cwd(),
"components",
"dashboard",
"scan-terminal",
"scan-terminal-client.ts",
),
"utf8",
);
assert.match(
scanTerminalClientSource,
/hasDirectBackendApiBaseUrl/,
"public scan terminal requests should only attach user auth in direct-backend mode so CDN caches can be shared through the Next proxy",
);
const overviewProxySource = fs.readFileSync(
path.join(
process.cwd(),
@@ -3,6 +3,7 @@
import {
buildBrowserBackendHeaders,
fetchBackendApi,
hasDirectBackendApiBaseUrl,
} from "@/lib/backend-api";
import { DASHBOARD_REFRESH_POLICY_MS } from "@/lib/refresh-policy";
import type {
@@ -144,11 +145,14 @@ async function getTerminal({
if (forceRefresh) {
params.set("_ts", String(Date.now()));
}
const headers = await buildBrowserBackendHeaders({ Accept: "application/json" });
const directBackend = hasDirectBackendApiBaseUrl();
const headers = directBackend
? await buildBrowserBackendHeaders({ Accept: "application/json" })
: new Headers({ Accept: "application/json" });
return readJsonOrThrow<ScanTerminalResponse>(
`/api/scan/terminal?${params.toString()}`,
{
cache: "no-store",
cache: forceRefresh || directBackend ? "no-store" : "default",
headers,
signal,
},