Use the sites if they are offline for now

This commit is contained in:
Owen
2025-08-19 22:07:52 -07:00
parent 25cef26251
commit 7de8bb00e7

View File

@@ -98,6 +98,7 @@ export async function getTraefikConfig(
type: string; type: string;
subnet: string | null; subnet: string | null;
exitNodeId: number | null; exitNodeId: number | null;
online: boolean;
}; };
}; };
@@ -142,7 +143,6 @@ export async function getTraefikConfig(
and( and(
eq(targets.enabled, true), eq(targets.enabled, true),
eq(resources.enabled, true), eq(resources.enabled, true),
eq(sites.online, true),
or( or(
eq(sites.exitNodeId, exitNodeId), eq(sites.exitNodeId, exitNodeId),
isNull(sites.exitNodeId) isNull(sites.exitNodeId)
@@ -189,7 +189,8 @@ export async function getTraefikConfig(
siteId: row.siteId, siteId: row.siteId,
type: row.siteType, type: row.siteType,
subnet: row.subnet, subnet: row.subnet,
exitNodeId: row.exitNodeId exitNodeId: row.exitNodeId,
online: row.siteOnline
} }
}); });
}); });
@@ -317,48 +318,67 @@ export async function getTraefikConfig(
config_output.http.services![serviceName] = { config_output.http.services![serviceName] = {
loadBalancer: { loadBalancer: {
servers: (targets as TargetWithSite[]) servers: (() => {
.filter((target: TargetWithSite) => { // Check if any sites are online
if (!target.enabled) { // THIS IS SO THAT THERE IS SOME IMMEDIATE FEEDBACK
return false; // EVEN IF THE SITES HAVE NOT UPDATED YET FROM THE
} // RECEIVE BANDWIDTH ENDPOINT.
if (
target.site.type === "local" || // TODO: HOW TO HANDLE ^^^^^^ BETTER
target.site.type === "wireguard" const anySitesOnline = (
) { targets as TargetWithSite[]
if ( ).some((target: TargetWithSite) => target.site.online);
!target.ip ||
!target.port || return (targets as TargetWithSite[])
!target.method .filter((target: TargetWithSite) => {
) { if (!target.enabled) {
return false; return false;
} }
} else if (target.site.type === "newt") {
if ( // If any sites are online, exclude offline sites
!target.internalPort || if (anySitesOnline && !target.site.online) {
!target.method ||
!target.site.subnet
) {
return false; return false;
} }
}
return true; if (
}) target.site.type === "local" ||
.map((target: TargetWithSite) => { target.site.type === "wireguard"
if ( ) {
target.site.type === "local" || if (
target.site.type === "wireguard" !target.ip ||
) { !target.port ||
return { !target.method
url: `${target.method}://${target.ip}:${target.port}` ) {
}; return false;
} else if (target.site.type === "newt") { }
const ip = target.site.subnet!.split("/")[0]; } else if (target.site.type === "newt") {
return { if (
url: `${target.method}://${ip}:${target.internalPort}` !target.internalPort ||
}; !target.method ||
} !target.site.subnet
}), ) {
return false;
}
}
return true;
})
.map((target: TargetWithSite) => {
if (
target.site.type === "local" ||
target.site.type === "wireguard"
) {
return {
url: `${target.method}://${target.ip}:${target.port}`
};
} else if (target.site.type === "newt") {
const ip =
target.site.subnet!.split("/")[0];
return {
url: `${target.method}://${ip}:${target.internalPort}`
};
}
});
})(),
...(resource.stickySession ...(resource.stickySession
? { ? {
sticky: { sticky: {
@@ -437,43 +457,57 @@ export async function getTraefikConfig(
config_output[protocol].services[serviceName] = { config_output[protocol].services[serviceName] = {
loadBalancer: { loadBalancer: {
servers: (targets as TargetWithSite[]) servers: (() => {
.filter((target: TargetWithSite) => { // Check if any sites are online
if (!target.enabled) { const anySitesOnline = (
return false; targets as TargetWithSite[]
} ).some((target: TargetWithSite) => target.site.online);
if (
target.site.type === "local" || return (targets as TargetWithSite[])
target.site.type === "wireguard" .filter((target: TargetWithSite) => {
) { if (!target.enabled) {
if (!target.ip || !target.port) {
return false; return false;
} }
} else if (target.site.type === "newt") {
// If any sites are online, exclude offline sites
if (anySitesOnline && !target.site.online) {
return false;
}
if ( if (
!target.internalPort || target.site.type === "local" ||
!target.site.subnet target.site.type === "wireguard"
) { ) {
return false; if (!target.ip || !target.port) {
return false;
}
} else if (target.site.type === "newt") {
if (
!target.internalPort ||
!target.site.subnet
) {
return false;
}
} }
} return true;
return true; })
}) .map((target: TargetWithSite) => {
.map((target: TargetWithSite) => { if (
if ( target.site.type === "local" ||
target.site.type === "local" || target.site.type === "wireguard"
target.site.type === "wireguard" ) {
) { return {
return { address: `${target.ip}:${target.port}`
address: `${target.ip}:${target.port}` };
}; } else if (target.site.type === "newt") {
} else if (target.site.type === "newt") { const ip =
const ip = target.site.subnet!.split("/")[0]; target.site.subnet!.split("/")[0];
return { return {
address: `${ip}:${target.internalPort}` address: `${ip}:${target.internalPort}`
}; };
} }
}), });
})(),
...(resource.stickySession ...(resource.stickySession
? { ? {
sticky: { sticky: {