fix: enforce dev report port lifecycle

This commit is contained in:
HWLAB Code Queue
2026-05-22 11:51:02 +00:00
parent f933a81c83
commit d81b909cf4
6 changed files with 387 additions and 5 deletions
+42 -2
View File
@@ -4,15 +4,55 @@ export const DEPRECATED_DEV_PUBLIC_ENDPOINT = "http://74.48.78.17:6667";
export const DEPRECATED_RESERVED_PROD_ENDPOINT = "http://74.48.78.17:6666";
export const REPORT_LIFECYCLE_VERSION = "v1";
export const deprecatedPublicPorts = Object.freeze([6666, 6667]);
export const deprecatedPublicEndpoints = Object.freeze([
DEPRECATED_DEV_PUBLIC_ENDPOINT,
DEPRECATED_RESERVED_PROD_ENDPOINT
]);
const deprecatedPublicEndpointPattern = /http:\/\/74\.48\.78\.17:666[67]\b/gu;
const deprecatedPublicEndpointPattern = /\bhttps?:\/\/74\.48\.78\.17:(666[67])(?=[/?#\s"'`),\]}]|$)/giu;
const deprecatedPublicHostPortPattern = /(?<!\/\/)\b74\.48\.78\.17:(666[67])(?=[/?#\s"'`),\]}]|$)/giu;
const endpointContextWords = [
"active",
"api",
"browser",
"current",
"deprecated",
"edge",
"endpoint",
"frontend",
"health",
"historical",
"ingress",
"legacy",
"public",
"route"
].join("|");
const deprecatedPublicPortContextPattern = new RegExp(
`\\b(?:${endpointContextWords})\\b[^.\\n]{0,80}(?<![A-Za-z0-9.-]):(666[67])\\b|(?<![A-Za-z0-9.-]):(666[67])\\b[^.\\n]{0,80}\\b(?:${endpointContextWords})\\b`,
"giu"
);
function endpointForPort(port) {
if (Number(port) === 6666) return DEPRECATED_RESERVED_PROD_ENDPOINT;
if (Number(port) === 6667) return DEPRECATED_DEV_PUBLIC_ENDPOINT;
throw new Error(`unsupported deprecated public port ${port}`);
}
function addMatches(matches, pattern, text) {
pattern.lastIndex = 0;
for (const match of String(text).matchAll(pattern)) {
const port = match[1] ?? match[2];
matches.add(endpointForPort(port));
}
}
export function findDeprecatedPublicEndpoints(text) {
return [...new Set(String(text).match(deprecatedPublicEndpointPattern) ?? [])].sort();
const matches = new Set();
addMatches(matches, deprecatedPublicEndpointPattern, text);
addMatches(matches, deprecatedPublicHostPortPattern, text);
addMatches(matches, deprecatedPublicPortContextPattern, text);
return [...matches].sort();
}
export function isDeprecatedEndpointAllowedInActiveReport(report, endpoint) {