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,11 +318,28 @@ export async function getTraefikConfig(
config_output.http.services![serviceName] = { config_output.http.services![serviceName] = {
loadBalancer: { loadBalancer: {
servers: (targets as TargetWithSite[]) servers: (() => {
// Check if any sites are online
// THIS IS SO THAT THERE IS SOME IMMEDIATE FEEDBACK
// EVEN IF THE SITES HAVE NOT UPDATED YET FROM THE
// RECEIVE BANDWIDTH ENDPOINT.
// TODO: HOW TO HANDLE ^^^^^^ BETTER
const anySitesOnline = (
targets as TargetWithSite[]
).some((target: TargetWithSite) => target.site.online);
return (targets as TargetWithSite[])
.filter((target: TargetWithSite) => { .filter((target: TargetWithSite) => {
if (!target.enabled) { if (!target.enabled) {
return false; return false;
} }
// If any sites are online, exclude offline sites
if (anySitesOnline && !target.site.online) {
return false;
}
if ( if (
target.site.type === "local" || target.site.type === "local" ||
target.site.type === "wireguard" target.site.type === "wireguard"
@@ -353,12 +371,14 @@ export async function getTraefikConfig(
url: `${target.method}://${target.ip}:${target.port}` url: `${target.method}://${target.ip}:${target.port}`
}; };
} else if (target.site.type === "newt") { } else if (target.site.type === "newt") {
const ip = target.site.subnet!.split("/")[0]; const ip =
target.site.subnet!.split("/")[0];
return { return {
url: `${target.method}://${ip}:${target.internalPort}` url: `${target.method}://${ip}:${target.internalPort}`
}; };
} }
}), });
})(),
...(resource.stickySession ...(resource.stickySession
? { ? {
sticky: { sticky: {
@@ -437,11 +457,23 @@ export async function getTraefikConfig(
config_output[protocol].services[serviceName] = { config_output[protocol].services[serviceName] = {
loadBalancer: { loadBalancer: {
servers: (targets as TargetWithSite[]) servers: (() => {
// Check if any sites are online
const anySitesOnline = (
targets as TargetWithSite[]
).some((target: TargetWithSite) => target.site.online);
return (targets as TargetWithSite[])
.filter((target: TargetWithSite) => { .filter((target: TargetWithSite) => {
if (!target.enabled) { if (!target.enabled) {
return false; return false;
} }
// If any sites are online, exclude offline sites
if (anySitesOnline && !target.site.online) {
return false;
}
if ( if (
target.site.type === "local" || target.site.type === "local" ||
target.site.type === "wireguard" target.site.type === "wireguard"
@@ -468,12 +500,14 @@ export async function getTraefikConfig(
address: `${target.ip}:${target.port}` address: `${target.ip}:${target.port}`
}; };
} else if (target.site.type === "newt") { } else if (target.site.type === "newt") {
const ip = target.site.subnet!.split("/")[0]; const ip =
target.site.subnet!.split("/")[0];
return { return {
address: `${ip}:${target.internalPort}` address: `${ip}:${target.internalPort}`
}; };
} }
}), });
})(),
...(resource.stickySession ...(resource.stickySession
? { ? {
sticky: { sticky: {