mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-06 04:31:22 +02:00
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { SiteResource } from "@server/db";
|
|
|
|
export type SiteResourceDestinationInput = {
|
|
mode: SiteResource["mode"];
|
|
destination: string | null;
|
|
destinationPort: number | null;
|
|
scheme: "http" | "https" | null;
|
|
};
|
|
|
|
export function resolveHttpHttpsDisplayPort(
|
|
mode: "http",
|
|
destinationPort: number | null
|
|
): number {
|
|
if (destinationPort != null) {
|
|
return destinationPort;
|
|
}
|
|
return 80;
|
|
}
|
|
|
|
export function formatSiteResourceDestinationDisplay(
|
|
row: SiteResourceDestinationInput
|
|
): string {
|
|
if (!row.destination) {
|
|
return "";
|
|
}
|
|
const { mode, destination, destinationPort, scheme } = row;
|
|
if (mode !== "http") {
|
|
return destination;
|
|
}
|
|
const port = resolveHttpHttpsDisplayPort(mode, destinationPort);
|
|
const downstreamScheme = scheme ?? "http";
|
|
const hostPart =
|
|
destination.includes(":") && !destination.startsWith("[")
|
|
? `[${destination}]`
|
|
: destination;
|
|
return `${downstreamScheme}://${hostPart}:${port}`;
|
|
}
|