mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-06 02:36:38 +00:00
@@ -275,24 +275,26 @@ export const ConfigSchema = z
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
.refine(
|
.refine(
|
||||||
// Enforce proxy-port uniqueness within proxy-resources
|
// Enforce proxy-port uniqueness within proxy-resources per protocol
|
||||||
(config) => {
|
(config) => {
|
||||||
const proxyPortMap = new Map<number, string[]>();
|
const protocolPortMap = new Map<string, string[]>();
|
||||||
|
|
||||||
Object.entries(config["proxy-resources"]).forEach(
|
Object.entries(config["proxy-resources"]).forEach(
|
||||||
([resourceKey, resource]) => {
|
([resourceKey, resource]) => {
|
||||||
const proxyPort = resource["proxy-port"];
|
const proxyPort = resource["proxy-port"];
|
||||||
if (proxyPort !== undefined) {
|
const protocol = resource.protocol;
|
||||||
if (!proxyPortMap.has(proxyPort)) {
|
if (proxyPort !== undefined && protocol !== undefined) {
|
||||||
proxyPortMap.set(proxyPort, []);
|
const key = `${protocol}:${proxyPort}`;
|
||||||
|
if (!protocolPortMap.has(key)) {
|
||||||
|
protocolPortMap.set(key, []);
|
||||||
}
|
}
|
||||||
proxyPortMap.get(proxyPort)!.push(resourceKey);
|
protocolPortMap.get(key)!.push(resourceKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Find duplicates
|
// Find duplicates
|
||||||
const duplicates = Array.from(proxyPortMap.entries()).filter(
|
const duplicates = Array.from(protocolPortMap.entries()).filter(
|
||||||
([_, resourceKeys]) => resourceKeys.length > 1
|
([_, resourceKeys]) => resourceKeys.length > 1
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -300,25 +302,29 @@ export const ConfigSchema = z
|
|||||||
},
|
},
|
||||||
(config) => {
|
(config) => {
|
||||||
// Extract duplicates for error message
|
// Extract duplicates for error message
|
||||||
const proxyPortMap = new Map<number, string[]>();
|
const protocolPortMap = new Map<string, string[]>();
|
||||||
|
|
||||||
Object.entries(config["proxy-resources"]).forEach(
|
Object.entries(config["proxy-resources"]).forEach(
|
||||||
([resourceKey, resource]) => {
|
([resourceKey, resource]) => {
|
||||||
const proxyPort = resource["proxy-port"];
|
const proxyPort = resource["proxy-port"];
|
||||||
if (proxyPort !== undefined) {
|
const protocol = resource.protocol;
|
||||||
if (!proxyPortMap.has(proxyPort)) {
|
if (proxyPort !== undefined && protocol !== undefined) {
|
||||||
proxyPortMap.set(proxyPort, []);
|
const key = `${protocol}:${proxyPort}`;
|
||||||
|
if (!protocolPortMap.has(key)) {
|
||||||
|
protocolPortMap.set(key, []);
|
||||||
}
|
}
|
||||||
proxyPortMap.get(proxyPort)!.push(resourceKey);
|
protocolPortMap.get(key)!.push(resourceKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const duplicates = Array.from(proxyPortMap.entries())
|
const duplicates = Array.from(protocolPortMap.entries())
|
||||||
.filter(([_, resourceKeys]) => resourceKeys.length > 1)
|
.filter(([_, resourceKeys]) => resourceKeys.length > 1)
|
||||||
.map(
|
.map(
|
||||||
([proxyPort, resourceKeys]) =>
|
([protocolPort, resourceKeys]) => {
|
||||||
`port ${proxyPort} used by proxy-resources: ${resourceKeys.join(", ")}`
|
const [protocol, port] = protocolPort.split(':');
|
||||||
|
return `${protocol.toUpperCase()} port ${port} used by proxy-resources: ${resourceKeys.join(", ")}`;
|
||||||
|
}
|
||||||
)
|
)
|
||||||
.join("; ");
|
.join("; ");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user