mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-10 04:36:38 +00:00
Merge branch 'dev'
This commit is contained in:
2
.github/workflows/cicd.yml
vendored
2
.github/workflows/cicd.yml
vendored
@@ -3,7 +3,7 @@ name: CI/CD Pipeline
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- "*"
|
- "[0-9]+.[0-9]+.[0-9]+"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
|
|||||||
3
.github/workflows/test.yml
vendored
3
.github/workflows/test.yml
vendored
@@ -35,6 +35,9 @@ jobs:
|
|||||||
- name: Apply database migrations
|
- name: Apply database migrations
|
||||||
run: npm run db:sqlite:push
|
run: npm run db:sqlite:push
|
||||||
|
|
||||||
|
- name: Test with tsc
|
||||||
|
run: npx tsc --noEmit
|
||||||
|
|
||||||
- name: Start app in background
|
- name: Start app in background
|
||||||
run: nohup npm run dev &
|
run: nohup npm run dev &
|
||||||
|
|
||||||
|
|||||||
@@ -1333,7 +1333,7 @@
|
|||||||
"twoFactorRequired": "Двуфакторното удостоверяване е необходимо за регистрация на ключ за защита.",
|
"twoFactorRequired": "Двуфакторното удостоверяване е необходимо за регистрация на ключ за защита.",
|
||||||
"twoFactor": "Двуфакторно удостоверяване",
|
"twoFactor": "Двуфакторно удостоверяване",
|
||||||
"adminEnabled2FaOnYourAccount": "Вашият администратор е активирал двуфакторно удостоверяване за {email}. Моля, завършете процеса по настройка, за да продължите.",
|
"adminEnabled2FaOnYourAccount": "Вашият администратор е активирал двуфакторно удостоверяване за {email}. Моля, завършете процеса по настройка, за да продължите.",
|
||||||
"continueToApplication": "Продължаване към приложението",
|
"continueToApplication": "Продължете към приложението",
|
||||||
"securityKeyAdd": "Добавяне на ключ за сигурност",
|
"securityKeyAdd": "Добавяне на ключ за сигурност",
|
||||||
"securityKeyRegisterTitle": "Регистриране на нов ключ за сигурност",
|
"securityKeyRegisterTitle": "Регистриране на нов ключ за сигурност",
|
||||||
"securityKeyRegisterDescription": "Свържете ключа за сигурност и въведете име, по което да го идентифицирате",
|
"securityKeyRegisterDescription": "Свържете ключа за сигурност и въведете име, по което да го идентифицирате",
|
||||||
|
|||||||
@@ -1333,7 +1333,7 @@
|
|||||||
"twoFactorRequired": "Pro registraci bezpečnostního klíče je nutné dvoufaktorové ověření.",
|
"twoFactorRequired": "Pro registraci bezpečnostního klíče je nutné dvoufaktorové ověření.",
|
||||||
"twoFactor": "Dvoufaktorové ověření",
|
"twoFactor": "Dvoufaktorové ověření",
|
||||||
"adminEnabled2FaOnYourAccount": "Váš správce povolil dvoufaktorové ověřování pro {email}. Chcete-li pokračovat, dokončete proces nastavení.",
|
"adminEnabled2FaOnYourAccount": "Váš správce povolil dvoufaktorové ověřování pro {email}. Chcete-li pokračovat, dokončete proces nastavení.",
|
||||||
"continueToApplication": "Pokračovat do aplikace",
|
"continueToApplication": "Pokračovat v aplikaci",
|
||||||
"securityKeyAdd": "Přidat bezpečnostní klíč",
|
"securityKeyAdd": "Přidat bezpečnostní klíč",
|
||||||
"securityKeyRegisterTitle": "Registrovat nový bezpečnostní klíč",
|
"securityKeyRegisterTitle": "Registrovat nový bezpečnostní klíč",
|
||||||
"securityKeyRegisterDescription": "Připojte svůj bezpečnostní klíč a zadejte jméno pro jeho identifikaci",
|
"securityKeyRegisterDescription": "Připojte svůj bezpečnostní klíč a zadejte jméno pro jeho identifikaci",
|
||||||
|
|||||||
@@ -1333,7 +1333,7 @@
|
|||||||
"twoFactorRequired": "È richiesta l'autenticazione a due fattori per registrare una chiave di sicurezza.",
|
"twoFactorRequired": "È richiesta l'autenticazione a due fattori per registrare una chiave di sicurezza.",
|
||||||
"twoFactor": "Autenticazione a Due Fattori",
|
"twoFactor": "Autenticazione a Due Fattori",
|
||||||
"adminEnabled2FaOnYourAccount": "Il tuo amministratore ha abilitato l'autenticazione a due fattori per {email}. Completa il processo di configurazione per continuare.",
|
"adminEnabled2FaOnYourAccount": "Il tuo amministratore ha abilitato l'autenticazione a due fattori per {email}. Completa il processo di configurazione per continuare.",
|
||||||
"continueToApplication": "Continua all'Applicazione",
|
"continueToApplication": "Continua con l'applicazione",
|
||||||
"securityKeyAdd": "Aggiungi Chiave di Sicurezza",
|
"securityKeyAdd": "Aggiungi Chiave di Sicurezza",
|
||||||
"securityKeyRegisterTitle": "Registra Nuova Chiave di Sicurezza",
|
"securityKeyRegisterTitle": "Registra Nuova Chiave di Sicurezza",
|
||||||
"securityKeyRegisterDescription": "Collega la tua chiave di sicurezza e inserisci un nome per identificarla",
|
"securityKeyRegisterDescription": "Collega la tua chiave di sicurezza e inserisci un nome per identificarla",
|
||||||
|
|||||||
@@ -1333,7 +1333,7 @@
|
|||||||
"twoFactorRequired": "Tweestapsverificatie is vereist om een beveiligingssleutel te registreren.",
|
"twoFactorRequired": "Tweestapsverificatie is vereist om een beveiligingssleutel te registreren.",
|
||||||
"twoFactor": "Tweestapsverificatie",
|
"twoFactor": "Tweestapsverificatie",
|
||||||
"adminEnabled2FaOnYourAccount": "Je beheerder heeft tweestapsverificatie voor {email} ingeschakeld. Voltooi het instellingsproces om verder te gaan.",
|
"adminEnabled2FaOnYourAccount": "Je beheerder heeft tweestapsverificatie voor {email} ingeschakeld. Voltooi het instellingsproces om verder te gaan.",
|
||||||
"continueToApplication": "Doorgaan naar de applicatie",
|
"continueToApplication": "Doorgaan naar applicatie",
|
||||||
"securityKeyAdd": "Beveiligingssleutel toevoegen",
|
"securityKeyAdd": "Beveiligingssleutel toevoegen",
|
||||||
"securityKeyRegisterTitle": "Nieuwe beveiligingssleutel registreren",
|
"securityKeyRegisterTitle": "Nieuwe beveiligingssleutel registreren",
|
||||||
"securityKeyRegisterDescription": "Verbind je beveiligingssleutel en voer een naam in om deze te identificeren",
|
"securityKeyRegisterDescription": "Verbind je beveiligingssleutel en voer een naam in om deze te identificeren",
|
||||||
|
|||||||
@@ -1333,7 +1333,7 @@
|
|||||||
"twoFactorRequired": "A autenticação de dois fatores é necessária para registrar uma chave de segurança.",
|
"twoFactorRequired": "A autenticação de dois fatores é necessária para registrar uma chave de segurança.",
|
||||||
"twoFactor": "Autenticação de Dois Fatores",
|
"twoFactor": "Autenticação de Dois Fatores",
|
||||||
"adminEnabled2FaOnYourAccount": "Seu administrador ativou a autenticação de dois fatores para {email}. Complete o processo de configuração para continuar.",
|
"adminEnabled2FaOnYourAccount": "Seu administrador ativou a autenticação de dois fatores para {email}. Complete o processo de configuração para continuar.",
|
||||||
"continueToApplication": "Continuar para Aplicativo",
|
"continueToApplication": "Continuar para o aplicativo",
|
||||||
"securityKeyAdd": "Adicionar Chave de Segurança",
|
"securityKeyAdd": "Adicionar Chave de Segurança",
|
||||||
"securityKeyRegisterTitle": "Registrar Nova Chave de Segurança",
|
"securityKeyRegisterTitle": "Registrar Nova Chave de Segurança",
|
||||||
"securityKeyRegisterDescription": "Conecte sua chave de segurança e insira um nome para identificá-la",
|
"securityKeyRegisterDescription": "Conecte sua chave de segurança e insira um nome para identificá-la",
|
||||||
|
|||||||
@@ -1333,7 +1333,7 @@
|
|||||||
"twoFactorRequired": "注册安全密钥需要两步验证。",
|
"twoFactorRequired": "注册安全密钥需要两步验证。",
|
||||||
"twoFactor": "两步验证",
|
"twoFactor": "两步验证",
|
||||||
"adminEnabled2FaOnYourAccount": "管理员已为{email}启用两步验证。请完成设置以继续。",
|
"adminEnabled2FaOnYourAccount": "管理员已为{email}启用两步验证。请完成设置以继续。",
|
||||||
"continueToApplication": "继续到应用程序",
|
"continueToApplication": "继续应用",
|
||||||
"securityKeyAdd": "添加安全密钥",
|
"securityKeyAdd": "添加安全密钥",
|
||||||
"securityKeyRegisterTitle": "注册新安全密钥",
|
"securityKeyRegisterTitle": "注册新安全密钥",
|
||||||
"securityKeyRegisterDescription": "连接您的安全密钥并输入名称以便识别",
|
"securityKeyRegisterDescription": "连接您的安全密钥并输入名称以便识别",
|
||||||
|
|||||||
2346
package-lock.json
generated
2346
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -35,11 +35,12 @@ function createDb() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create connection pools instead of individual connections
|
// Create connection pools instead of individual connections
|
||||||
|
const poolConfig = config.postgres.pool;
|
||||||
const primaryPool = new Pool({
|
const primaryPool = new Pool({
|
||||||
connectionString,
|
connectionString,
|
||||||
max: 20,
|
max: poolConfig.max_connections,
|
||||||
idleTimeoutMillis: 30000,
|
idleTimeoutMillis: poolConfig.idle_timeout_ms,
|
||||||
connectionTimeoutMillis: 5000,
|
connectionTimeoutMillis: poolConfig.connection_timeout_ms,
|
||||||
});
|
});
|
||||||
|
|
||||||
const replicas = [];
|
const replicas = [];
|
||||||
@@ -50,9 +51,9 @@ function createDb() {
|
|||||||
for (const conn of replicaConnections) {
|
for (const conn of replicaConnections) {
|
||||||
const replicaPool = new Pool({
|
const replicaPool = new Pool({
|
||||||
connectionString: conn.connection_string,
|
connectionString: conn.connection_string,
|
||||||
max: 10,
|
max: poolConfig.max_replica_connections,
|
||||||
idleTimeoutMillis: 30000,
|
idleTimeoutMillis: poolConfig.idle_timeout_ms,
|
||||||
connectionTimeoutMillis: 5000,
|
connectionTimeoutMillis: poolConfig.connection_timeout_ms,
|
||||||
});
|
});
|
||||||
replicas.push(DrizzlePostgres(replicaPool));
|
replicas.push(DrizzlePostgres(replicaPool));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,7 +125,8 @@ export const targets = pgTable("targets", {
|
|||||||
path: text("path"),
|
path: text("path"),
|
||||||
pathMatchType: text("pathMatchType"), // exact, prefix, regex
|
pathMatchType: text("pathMatchType"), // exact, prefix, regex
|
||||||
rewritePath: text("rewritePath"), // if set, rewrites the path to this value before sending to the target
|
rewritePath: text("rewritePath"), // if set, rewrites the path to this value before sending to the target
|
||||||
rewritePathType: text("rewritePathType") // exact, prefix, regex, stripPrefix
|
rewritePathType: text("rewritePathType"), // exact, prefix, regex, stripPrefix
|
||||||
|
priority: integer("priority").notNull().default(100)
|
||||||
});
|
});
|
||||||
|
|
||||||
export const targetHealthCheck = pgTable("targetHealthCheck", {
|
export const targetHealthCheck = pgTable("targetHealthCheck", {
|
||||||
|
|||||||
@@ -137,7 +137,8 @@ export const targets = sqliteTable("targets", {
|
|||||||
path: text("path"),
|
path: text("path"),
|
||||||
pathMatchType: text("pathMatchType"), // exact, prefix, regex
|
pathMatchType: text("pathMatchType"), // exact, prefix, regex
|
||||||
rewritePath: text("rewritePath"), // if set, rewrites the path to this value before sending to the target
|
rewritePath: text("rewritePath"), // if set, rewrites the path to this value before sending to the target
|
||||||
rewritePathType: text("rewritePathType") // exact, prefix, regex, stripPrefix
|
rewritePathType: text("rewritePathType"), // exact, prefix, regex, stripPrefix
|
||||||
|
priority: integer("priority").notNull().default(100)
|
||||||
});
|
});
|
||||||
|
|
||||||
export const targetHealthCheck = sqliteTable("targetHealthCheck", {
|
export const targetHealthCheck = sqliteTable("targetHealthCheck", {
|
||||||
|
|||||||
@@ -115,7 +115,8 @@ export async function updateProxyResources(
|
|||||||
path: targetData.path,
|
path: targetData.path,
|
||||||
pathMatchType: targetData["path-match"],
|
pathMatchType: targetData["path-match"],
|
||||||
rewritePath: targetData.rewritePath,
|
rewritePath: targetData.rewritePath,
|
||||||
rewritePathType: targetData["rewrite-match"]
|
rewritePathType: targetData["rewrite-match"],
|
||||||
|
priority: targetData.priority
|
||||||
})
|
})
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
@@ -392,7 +393,8 @@ export async function updateProxyResources(
|
|||||||
path: targetData.path,
|
path: targetData.path,
|
||||||
pathMatchType: targetData["path-match"],
|
pathMatchType: targetData["path-match"],
|
||||||
rewritePath: targetData.rewritePath,
|
rewritePath: targetData.rewritePath,
|
||||||
rewritePathType: targetData["rewrite-match"]
|
rewritePathType: targetData["rewrite-match"],
|
||||||
|
priority: targetData.priority
|
||||||
})
|
})
|
||||||
.where(eq(targets.targetId, existingTarget.targetId))
|
.where(eq(targets.targetId, existingTarget.targetId))
|
||||||
.returning();
|
.returning();
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ export const TargetSchema = z.object({
|
|||||||
"path-match": z.enum(["exact", "prefix", "regex"]).optional().nullable(),
|
"path-match": z.enum(["exact", "prefix", "regex"]).optional().nullable(),
|
||||||
healthcheck: TargetHealthCheckSchema.optional(),
|
healthcheck: TargetHealthCheckSchema.optional(),
|
||||||
rewritePath: z.string().optional(),
|
rewritePath: z.string().optional(),
|
||||||
"rewrite-match": z.enum(["exact", "prefix", "regex", "stripPrefix"]).optional().nullable()
|
"rewrite-match": z.enum(["exact", "prefix", "regex", "stripPrefix"]).optional().nullable(),
|
||||||
|
priority: z.number().int().min(1).max(1000).optional().default(100)
|
||||||
});
|
});
|
||||||
export type TargetData = z.infer<typeof TargetSchema>;
|
export type TargetData = z.infer<typeof TargetSchema>;
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ export const configSchema = z
|
|||||||
server: z.object({
|
server: z.object({
|
||||||
integration_port: portSchema
|
integration_port: portSchema
|
||||||
.optional()
|
.optional()
|
||||||
.default(3004)
|
.default(3003)
|
||||||
.transform(stoi)
|
.transform(stoi)
|
||||||
.pipe(portSchema.optional()),
|
.pipe(portSchema.optional()),
|
||||||
external_port: portSchema
|
external_port: portSchema
|
||||||
@@ -158,7 +158,21 @@ export const configSchema = z
|
|||||||
connection_string: z.string()
|
connection_string: z.string()
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
.optional(),
|
||||||
|
pool: z
|
||||||
|
.object({
|
||||||
|
max_connections: z.number().positive().optional().default(20),
|
||||||
|
max_replica_connections: z.number().positive().optional().default(10),
|
||||||
|
idle_timeout_ms: z.number().positive().optional().default(30000),
|
||||||
|
connection_timeout_ms: z.number().positive().optional().default(5000)
|
||||||
|
})
|
||||||
.optional()
|
.optional()
|
||||||
|
.default({
|
||||||
|
max_connections: 20,
|
||||||
|
max_replica_connections: 10,
|
||||||
|
idle_timeout_ms: 30000,
|
||||||
|
connection_timeout_ms: 5000
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
traefik: z
|
traefik: z
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { db, exitNodes, targetHealthCheck } from "@server/db";
|
import { db, exitNodes, targetHealthCheck } from "@server/db";
|
||||||
import { and, eq, inArray, or, isNull, ne, isNotNull } from "drizzle-orm";
|
import { and, eq, inArray, or, isNull, ne, isNotNull, desc } from "drizzle-orm";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import config from "@server/lib/config";
|
import config from "@server/lib/config";
|
||||||
import { orgs, resources, sites, Target, targets } from "@server/db";
|
import { orgs, resources, sites, Target, targets } from "@server/db";
|
||||||
@@ -59,6 +59,8 @@ export async function getTraefikConfig(
|
|||||||
pathMatchType: targets.pathMatchType,
|
pathMatchType: targets.pathMatchType,
|
||||||
rewritePath: targets.rewritePath,
|
rewritePath: targets.rewritePath,
|
||||||
rewritePathType: targets.rewritePathType,
|
rewritePathType: targets.rewritePathType,
|
||||||
|
priority: targets.priority,
|
||||||
|
|
||||||
// Site fields
|
// Site fields
|
||||||
siteId: sites.siteId,
|
siteId: sites.siteId,
|
||||||
siteType: sites.type,
|
siteType: sites.type,
|
||||||
@@ -87,7 +89,8 @@ export async function getTraefikConfig(
|
|||||||
? isNotNull(resources.http) // ignore the http check if allow_raw_resources is true
|
? isNotNull(resources.http) // ignore the http check if allow_raw_resources is true
|
||||||
: eq(resources.http, true)
|
: eq(resources.http, true)
|
||||||
)
|
)
|
||||||
);
|
)
|
||||||
|
.orderBy(desc(targets.priority), targets.targetId); // stable ordering
|
||||||
|
|
||||||
// Group by resource and include targets with their unique site data
|
// Group by resource and include targets with their unique site data
|
||||||
const resourcesMap = new Map();
|
const resourcesMap = new Map();
|
||||||
@@ -99,6 +102,7 @@ export async function getTraefikConfig(
|
|||||||
const pathMatchType = row.pathMatchType || "";
|
const pathMatchType = row.pathMatchType || "";
|
||||||
const rewritePath = row.rewritePath || "";
|
const rewritePath = row.rewritePath || "";
|
||||||
const rewritePathType = row.rewritePathType || "";
|
const rewritePathType = row.rewritePathType || "";
|
||||||
|
const priority = row.priority ?? 100;
|
||||||
|
|
||||||
// Create a unique key combining resourceId, path config, and rewrite config
|
// Create a unique key combining resourceId, path config, and rewrite config
|
||||||
const pathKey = [targetPath, pathMatchType, rewritePath, rewritePathType]
|
const pathKey = [targetPath, pathMatchType, rewritePath, rewritePathType]
|
||||||
@@ -140,7 +144,8 @@ export async function getTraefikConfig(
|
|||||||
path: row.path, // the targets will all have the same path
|
path: row.path, // the targets will all have the same path
|
||||||
pathMatchType: row.pathMatchType, // the targets will all have the same pathMatchType
|
pathMatchType: row.pathMatchType, // the targets will all have the same pathMatchType
|
||||||
rewritePath: row.rewritePath,
|
rewritePath: row.rewritePath,
|
||||||
rewritePathType: row.rewritePathType
|
rewritePathType: row.rewritePathType,
|
||||||
|
priority: priority // may be null, we fallback later
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,6 +160,7 @@ export async function getTraefikConfig(
|
|||||||
enabled: row.targetEnabled,
|
enabled: row.targetEnabled,
|
||||||
rewritePath: row.rewritePath,
|
rewritePath: row.rewritePath,
|
||||||
rewritePathType: row.rewritePathType,
|
rewritePathType: row.rewritePathType,
|
||||||
|
priority: row.priority,
|
||||||
site: {
|
site: {
|
||||||
siteId: row.siteId,
|
siteId: row.siteId,
|
||||||
type: row.siteType,
|
type: row.siteType,
|
||||||
@@ -338,10 +344,30 @@ export async function getTraefikConfig(
|
|||||||
|
|
||||||
// Build routing rules
|
// Build routing rules
|
||||||
let rule = `Host(\`${fullDomain}\`)`;
|
let rule = `Host(\`${fullDomain}\`)`;
|
||||||
let priority = 100;
|
|
||||||
|
// priority logic
|
||||||
|
let priority: number;
|
||||||
|
if (resource.priority && resource.priority != 100) {
|
||||||
|
priority = resource.priority;
|
||||||
|
} else {
|
||||||
|
priority = 100;
|
||||||
|
if (resource.path && resource.pathMatchType) {
|
||||||
|
priority += 10;
|
||||||
|
if (resource.pathMatchType === "exact") {
|
||||||
|
priority += 5;
|
||||||
|
} else if (resource.pathMatchType === "prefix") {
|
||||||
|
priority += 3;
|
||||||
|
} else if (resource.pathMatchType === "regex") {
|
||||||
|
priority += 2;
|
||||||
|
}
|
||||||
|
if (resource.path === "/") {
|
||||||
|
priority = 1; // lowest for catch-all
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (resource.path && resource.pathMatchType) {
|
if (resource.path && resource.pathMatchType) {
|
||||||
priority += 1;
|
// priority += 1;
|
||||||
// add path to rule based on match type
|
// add path to rule based on match type
|
||||||
let path = resource.path;
|
let path = resource.path;
|
||||||
// if the path doesn't start with a /, add it
|
// if the path doesn't start with a /, add it
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import {
|
|||||||
loginPage,
|
loginPage,
|
||||||
targetHealthCheck
|
targetHealthCheck
|
||||||
} from "@server/db";
|
} from "@server/db";
|
||||||
import { and, eq, inArray, or, isNull, ne, isNotNull } from "drizzle-orm";
|
import { and, eq, inArray, or, isNull, ne, isNotNull, desc } from "drizzle-orm";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import HttpCode from "@server/types/HttpCode";
|
import HttpCode from "@server/types/HttpCode";
|
||||||
import config from "@server/lib/config";
|
import config from "@server/lib/config";
|
||||||
@@ -78,7 +78,8 @@ export async function getTraefikConfig(
|
|||||||
hcHealth: targetHealthCheck.hcHealth,
|
hcHealth: targetHealthCheck.hcHealth,
|
||||||
path: targets.path,
|
path: targets.path,
|
||||||
pathMatchType: targets.pathMatchType,
|
pathMatchType: targets.pathMatchType,
|
||||||
|
priority: targets.priority,
|
||||||
|
|
||||||
// Site fields
|
// Site fields
|
||||||
siteId: sites.siteId,
|
siteId: sites.siteId,
|
||||||
siteType: sites.type,
|
siteType: sites.type,
|
||||||
@@ -119,7 +120,8 @@ export async function getTraefikConfig(
|
|||||||
? isNotNull(resources.http) // ignore the http check if allow_raw_resources is true
|
? isNotNull(resources.http) // ignore the http check if allow_raw_resources is true
|
||||||
: eq(resources.http, true)
|
: eq(resources.http, true)
|
||||||
)
|
)
|
||||||
);
|
)
|
||||||
|
.orderBy(desc(targets.priority), targets.targetId); // stable ordering
|
||||||
|
|
||||||
// Group by resource and include targets with their unique site data
|
// Group by resource and include targets with their unique site data
|
||||||
const resourcesMap = new Map();
|
const resourcesMap = new Map();
|
||||||
@@ -129,6 +131,7 @@ export async function getTraefikConfig(
|
|||||||
const resourceName = sanitize(row.resourceName) || "";
|
const resourceName = sanitize(row.resourceName) || "";
|
||||||
const targetPath = sanitize(row.path) || ""; // Handle null/undefined paths
|
const targetPath = sanitize(row.path) || ""; // Handle null/undefined paths
|
||||||
const pathMatchType = row.pathMatchType || "";
|
const pathMatchType = row.pathMatchType || "";
|
||||||
|
const priority = row.priority ?? 100;
|
||||||
|
|
||||||
if (filterOutNamespaceDomains && row.domainNamespaceId) {
|
if (filterOutNamespaceDomains && row.domainNamespaceId) {
|
||||||
return;
|
return;
|
||||||
@@ -159,7 +162,8 @@ export async function getTraefikConfig(
|
|||||||
targets: [],
|
targets: [],
|
||||||
headers: row.headers,
|
headers: row.headers,
|
||||||
path: row.path, // the targets will all have the same path
|
path: row.path, // the targets will all have the same path
|
||||||
pathMatchType: row.pathMatchType // the targets will all have the same pathMatchType
|
pathMatchType: row.pathMatchType, // the targets will all have the same pathMatchType
|
||||||
|
priority: priority // may be null, we fallback later
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,6 +176,7 @@ export async function getTraefikConfig(
|
|||||||
port: row.port,
|
port: row.port,
|
||||||
internalPort: row.internalPort,
|
internalPort: row.internalPort,
|
||||||
enabled: row.targetEnabled,
|
enabled: row.targetEnabled,
|
||||||
|
priority: row.priority,
|
||||||
site: {
|
site: {
|
||||||
siteId: row.siteId,
|
siteId: row.siteId,
|
||||||
type: row.siteType,
|
type: row.siteType,
|
||||||
@@ -335,9 +340,30 @@ export async function getTraefikConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let rule = `Host(\`${fullDomain}\`)`;
|
let rule = `Host(\`${fullDomain}\`)`;
|
||||||
let priority = 100;
|
|
||||||
|
// priority logic
|
||||||
|
let priority: number;
|
||||||
|
if (resource.priority && resource.priority != 100) {
|
||||||
|
priority = resource.priority;
|
||||||
|
} else {
|
||||||
|
priority = 100;
|
||||||
|
if (resource.path && resource.pathMatchType) {
|
||||||
|
priority += 10;
|
||||||
|
if (resource.pathMatchType === "exact") {
|
||||||
|
priority += 5;
|
||||||
|
} else if (resource.pathMatchType === "prefix") {
|
||||||
|
priority += 3;
|
||||||
|
} else if (resource.pathMatchType === "regex") {
|
||||||
|
priority += 2;
|
||||||
|
}
|
||||||
|
if (resource.path === "/") {
|
||||||
|
priority = 1; // lowest for catch-all
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (resource.path && resource.pathMatchType) {
|
if (resource.path && resource.pathMatchType) {
|
||||||
priority += 1;
|
//priority += 1;
|
||||||
// add path to rule based on match type
|
// add path to rule based on match type
|
||||||
let path = resource.path;
|
let path = resource.path;
|
||||||
// if the path doesn't start with a /, add it
|
// if the path doesn't start with a /, add it
|
||||||
@@ -393,7 +419,7 @@ export async function getTraefikConfig(
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
(targets as TargetWithSite[])
|
(targets as TargetWithSite[])
|
||||||
.filter((target: TargetWithSite) => {
|
.filter((target: TargetWithSite) => {
|
||||||
if (!target.enabled) {
|
if (!target.enabled) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -414,7 +440,7 @@ export async function getTraefikConfig(
|
|||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (target.site.type === "newt") {
|
} else if (target.site.type === "newt") {
|
||||||
if (
|
if (
|
||||||
!target.internalPort ||
|
!target.internalPort ||
|
||||||
!target.method ||
|
!target.method ||
|
||||||
@@ -422,10 +448,10 @@ export async function getTraefikConfig(
|
|||||||
) {
|
) {
|
||||||
return false;
|
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"
|
||||||
@@ -433,14 +459,14 @@ export async function getTraefikConfig(
|
|||||||
return {
|
return {
|
||||||
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 =
|
const ip =
|
||||||
target.site.subnet!.split("/")[0];
|
target.site.subnet!.split("/")[0];
|
||||||
return {
|
return {
|
||||||
url: `${target.method}://${ip}:${target.internalPort}`
|
url: `${target.method}://${ip}:${target.internalPort}`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// filter out duplicates
|
// filter out duplicates
|
||||||
.filter(
|
.filter(
|
||||||
(v, i, a) =>
|
(v, i, a) =>
|
||||||
|
|||||||
@@ -53,7 +53,8 @@ const createTargetSchema = z
|
|||||||
path: z.string().optional().nullable(),
|
path: z.string().optional().nullable(),
|
||||||
pathMatchType: z.enum(["exact", "prefix", "regex"]).optional().nullable(),
|
pathMatchType: z.enum(["exact", "prefix", "regex"]).optional().nullable(),
|
||||||
rewritePath: z.string().optional().nullable(),
|
rewritePath: z.string().optional().nullable(),
|
||||||
rewritePathType: z.enum(["exact", "prefix", "regex", "stripPrefix"]).optional().nullable()
|
rewritePathType: z.enum(["exact", "prefix", "regex", "stripPrefix"]).optional().nullable(),
|
||||||
|
priority: z.number().int().min(1).max(1000)
|
||||||
})
|
})
|
||||||
.strict();
|
.strict();
|
||||||
|
|
||||||
@@ -210,7 +211,10 @@ export async function createTarget(
|
|||||||
internalPort,
|
internalPort,
|
||||||
enabled: targetData.enabled,
|
enabled: targetData.enabled,
|
||||||
path: targetData.path,
|
path: targetData.path,
|
||||||
pathMatchType: targetData.pathMatchType
|
pathMatchType: targetData.pathMatchType,
|
||||||
|
rewritePath: targetData.rewritePath,
|
||||||
|
rewritePathType: targetData.rewritePathType,
|
||||||
|
priority: targetData.priority
|
||||||
})
|
})
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,8 @@ function queryTargets(resourceId: number) {
|
|||||||
path: targets.path,
|
path: targets.path,
|
||||||
pathMatchType: targets.pathMatchType,
|
pathMatchType: targets.pathMatchType,
|
||||||
rewritePath: targets.rewritePath,
|
rewritePath: targets.rewritePath,
|
||||||
rewritePathType: targets.rewritePathType
|
rewritePathType: targets.rewritePathType,
|
||||||
|
priority: targets.priority,
|
||||||
})
|
})
|
||||||
.from(targets)
|
.from(targets)
|
||||||
.leftJoin(sites, eq(sites.siteId, targets.siteId))
|
.leftJoin(sites, eq(sites.siteId, targets.siteId))
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ const updateTargetBodySchema = z
|
|||||||
path: z.string().optional().nullable(),
|
path: z.string().optional().nullable(),
|
||||||
pathMatchType: z.enum(["exact", "prefix", "regex"]).optional().nullable(),
|
pathMatchType: z.enum(["exact", "prefix", "regex"]).optional().nullable(),
|
||||||
rewritePath: z.string().optional().nullable(),
|
rewritePath: z.string().optional().nullable(),
|
||||||
rewritePathType: z.enum(["exact", "prefix", "regex", "stripPrefix"]).optional().nullable()
|
rewritePathType: z.enum(["exact", "prefix", "regex", "stripPrefix"]).optional().nullable(),
|
||||||
|
priority: z.number().int().min(1).max(1000).optional(),
|
||||||
})
|
})
|
||||||
.strict()
|
.strict()
|
||||||
.refine((data) => Object.keys(data).length > 0, {
|
.refine((data) => Object.keys(data).length > 0, {
|
||||||
@@ -198,7 +199,10 @@ export async function updateTarget(
|
|||||||
internalPort,
|
internalPort,
|
||||||
enabled: parsedBody.data.enabled,
|
enabled: parsedBody.data.enabled,
|
||||||
path: parsedBody.data.path,
|
path: parsedBody.data.path,
|
||||||
pathMatchType: parsedBody.data.pathMatchType
|
pathMatchType: parsedBody.data.pathMatchType,
|
||||||
|
priority: parsedBody.data.priority,
|
||||||
|
rewritePath: parsedBody.data.rewritePath,
|
||||||
|
rewritePathType: parsedBody.data.rewritePathType
|
||||||
})
|
})
|
||||||
.where(eq(targets.targetId, targetId))
|
.where(eq(targets.targetId, targetId))
|
||||||
.returning();
|
.returning();
|
||||||
|
|||||||
@@ -74,7 +74,10 @@ import {
|
|||||||
CircleX,
|
CircleX,
|
||||||
ArrowRight,
|
ArrowRight,
|
||||||
Plus,
|
Plus,
|
||||||
MoveRight
|
MoveRight,
|
||||||
|
ArrowUp,
|
||||||
|
Info,
|
||||||
|
ArrowDown
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { ContainersSelector } from "@app/components/ContainersSelector";
|
import { ContainersSelector } from "@app/components/ContainersSelector";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
@@ -106,6 +109,7 @@ import {
|
|||||||
PathRewriteModal
|
PathRewriteModal
|
||||||
} from "@app/components/PathMatchRenameModal";
|
} from "@app/components/PathMatchRenameModal";
|
||||||
import { Badge } from "@app/components/ui/badge";
|
import { Badge } from "@app/components/ui/badge";
|
||||||
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@app/components/ui/tooltip";
|
||||||
|
|
||||||
const addTargetSchema = z
|
const addTargetSchema = z
|
||||||
.object({
|
.object({
|
||||||
@@ -122,7 +126,8 @@ const addTargetSchema = z
|
|||||||
rewritePathType: z
|
rewritePathType: z
|
||||||
.enum(["exact", "prefix", "regex", "stripPrefix"])
|
.enum(["exact", "prefix", "regex", "stripPrefix"])
|
||||||
.optional()
|
.optional()
|
||||||
.nullable()
|
.nullable(),
|
||||||
|
priority: z.number().int().min(1).max(1000)
|
||||||
})
|
})
|
||||||
.refine(
|
.refine(
|
||||||
(data) => {
|
(data) => {
|
||||||
@@ -301,7 +306,8 @@ export default function ReverseProxyTargets(props: {
|
|||||||
path: null,
|
path: null,
|
||||||
pathMatchType: null,
|
pathMatchType: null,
|
||||||
rewritePath: null,
|
rewritePath: null,
|
||||||
rewritePathType: null
|
rewritePathType: null,
|
||||||
|
priority: 100
|
||||||
} as z.infer<typeof addTargetSchema>
|
} as z.infer<typeof addTargetSchema>
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -485,6 +491,7 @@ export default function ReverseProxyTargets(props: {
|
|||||||
targetId: new Date().getTime(),
|
targetId: new Date().getTime(),
|
||||||
new: true,
|
new: true,
|
||||||
resourceId: resource.resourceId,
|
resourceId: resource.resourceId,
|
||||||
|
priority: 100,
|
||||||
hcEnabled: false,
|
hcEnabled: false,
|
||||||
hcPath: null,
|
hcPath: null,
|
||||||
hcMethod: null,
|
hcMethod: null,
|
||||||
@@ -509,7 +516,8 @@ export default function ReverseProxyTargets(props: {
|
|||||||
path: null,
|
path: null,
|
||||||
pathMatchType: null,
|
pathMatchType: null,
|
||||||
rewritePath: null,
|
rewritePath: null,
|
||||||
rewritePathType: null
|
rewritePathType: null,
|
||||||
|
priority: 100,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -587,7 +595,8 @@ export default function ReverseProxyTargets(props: {
|
|||||||
path: target.path,
|
path: target.path,
|
||||||
pathMatchType: target.pathMatchType,
|
pathMatchType: target.pathMatchType,
|
||||||
rewritePath: target.rewritePath,
|
rewritePath: target.rewritePath,
|
||||||
rewritePathType: target.rewritePathType
|
rewritePathType: target.rewritePathType,
|
||||||
|
priority: target.priority
|
||||||
};
|
};
|
||||||
|
|
||||||
if (target.new) {
|
if (target.new) {
|
||||||
@@ -660,6 +669,46 @@ export default function ReverseProxyTargets(props: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const columns: ColumnDef<LocalTarget>[] = [
|
const columns: ColumnDef<LocalTarget>[] = [
|
||||||
|
{
|
||||||
|
id: "priority",
|
||||||
|
header: () => (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
Priority
|
||||||
|
<TooltipProvider>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger>
|
||||||
|
<Info className="h-4 w-4 text-muted-foreground" />
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent className="max-w-xs">
|
||||||
|
<p>Higher priority routes are evaluated first. Priority = 100 means automatic ordering (system decides). Use another number to enforce manual priority.</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</TooltipProvider>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
min="1"
|
||||||
|
max="1000"
|
||||||
|
defaultValue={row.original.priority || 100}
|
||||||
|
className="w-20"
|
||||||
|
onBlur={(e) => {
|
||||||
|
const value = parseInt(e.target.value, 10);
|
||||||
|
if (value >= 1 && value <= 1000) {
|
||||||
|
updateTarget(row.original.targetId, {
|
||||||
|
...row.original,
|
||||||
|
priority: value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "path",
|
accessorKey: "path",
|
||||||
header: t("matchPath"),
|
header: t("matchPath"),
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ import {
|
|||||||
} from "@app/components/ui/popover";
|
} from "@app/components/ui/popover";
|
||||||
import { CaretSortIcon, CheckIcon } from "@radix-ui/react-icons";
|
import { CaretSortIcon, CheckIcon } from "@radix-ui/react-icons";
|
||||||
import { cn } from "@app/lib/cn";
|
import { cn } from "@app/lib/cn";
|
||||||
import { ArrowRight, MoveRight, Plus, SquareArrowOutUpRight } from "lucide-react";
|
import { ArrowRight, Info, MoveRight, Plus, SquareArrowOutUpRight } from "lucide-react";
|
||||||
import CopyTextBox from "@app/components/CopyTextBox";
|
import CopyTextBox from "@app/components/CopyTextBox";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
@@ -92,6 +92,7 @@ import { parseHostTarget } from "@app/lib/parseHostTarget";
|
|||||||
import { toASCII, toUnicode } from 'punycode';
|
import { toASCII, toUnicode } from 'punycode';
|
||||||
import { DomainRow } from "../../../../../components/DomainsTable";
|
import { DomainRow } from "../../../../../components/DomainsTable";
|
||||||
import { finalizeSubdomainSanitize } from "@app/lib/subdomain-utils";
|
import { finalizeSubdomainSanitize } from "@app/lib/subdomain-utils";
|
||||||
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@app/components/ui/tooltip";
|
||||||
import { PathMatchDisplay, PathMatchModal, PathRewriteDisplay, PathRewriteModal } from "@app/components/PathMatchRenameModal";
|
import { PathMatchDisplay, PathMatchModal, PathRewriteDisplay, PathRewriteModal } from "@app/components/PathMatchRenameModal";
|
||||||
|
|
||||||
|
|
||||||
@@ -119,7 +120,8 @@ const addTargetSchema = z.object({
|
|||||||
path: z.string().optional().nullable(),
|
path: z.string().optional().nullable(),
|
||||||
pathMatchType: z.enum(["exact", "prefix", "regex"]).optional().nullable(),
|
pathMatchType: z.enum(["exact", "prefix", "regex"]).optional().nullable(),
|
||||||
rewritePath: z.string().optional().nullable(),
|
rewritePath: z.string().optional().nullable(),
|
||||||
rewritePathType: z.enum(["exact", "prefix", "regex", "stripPrefix"]).optional().nullable()
|
rewritePathType: z.enum(["exact", "prefix", "regex", "stripPrefix"]).optional().nullable(),
|
||||||
|
priority: z.number().int().min(1).max(1000)
|
||||||
}).refine(
|
}).refine(
|
||||||
(data) => {
|
(data) => {
|
||||||
// If path is provided, pathMatchType must be provided
|
// If path is provided, pathMatchType must be provided
|
||||||
@@ -262,6 +264,7 @@ export default function Page() {
|
|||||||
pathMatchType: null,
|
pathMatchType: null,
|
||||||
rewritePath: null,
|
rewritePath: null,
|
||||||
rewritePathType: null,
|
rewritePathType: null,
|
||||||
|
priority: 100,
|
||||||
} as z.infer<typeof addTargetSchema>
|
} as z.infer<typeof addTargetSchema>
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -341,6 +344,7 @@ export default function Page() {
|
|||||||
targetId: new Date().getTime(),
|
targetId: new Date().getTime(),
|
||||||
new: true,
|
new: true,
|
||||||
resourceId: 0, // Will be set when resource is created
|
resourceId: 0, // Will be set when resource is created
|
||||||
|
priority: 100, // Default priority
|
||||||
hcEnabled: false,
|
hcEnabled: false,
|
||||||
hcPath: null,
|
hcPath: null,
|
||||||
hcMethod: null,
|
hcMethod: null,
|
||||||
@@ -366,6 +370,7 @@ export default function Page() {
|
|||||||
pathMatchType: null,
|
pathMatchType: null,
|
||||||
rewritePath: null,
|
rewritePath: null,
|
||||||
rewritePathType: null,
|
rewritePathType: null,
|
||||||
|
priority: 100,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,7 +480,8 @@ export default function Page() {
|
|||||||
path: target.path,
|
path: target.path,
|
||||||
pathMatchType: target.pathMatchType,
|
pathMatchType: target.pathMatchType,
|
||||||
rewritePath: target.rewritePath,
|
rewritePath: target.rewritePath,
|
||||||
rewritePathType: target.rewritePathType
|
rewritePathType: target.rewritePathType,
|
||||||
|
priority: target.priority
|
||||||
};
|
};
|
||||||
|
|
||||||
await api.put(`/resource/${id}/target`, data);
|
await api.put(`/resource/${id}/target`, data);
|
||||||
@@ -598,6 +604,46 @@ export default function Page() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const columns: ColumnDef<LocalTarget>[] = [
|
const columns: ColumnDef<LocalTarget>[] = [
|
||||||
|
{
|
||||||
|
id: "priority",
|
||||||
|
header: () => (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
Priority
|
||||||
|
<TooltipProvider>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger>
|
||||||
|
<Info className="h-4 w-4 text-muted-foreground" />
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent className="max-w-xs">
|
||||||
|
<p>Higher priority routes are evaluated first. Priority = 100 means automatic ordering (system decides). Use another number to enforce manual priority.</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</TooltipProvider>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
min="1"
|
||||||
|
max="1000"
|
||||||
|
defaultValue={row.original.priority || 100}
|
||||||
|
className="w-20"
|
||||||
|
onBlur={(e) => {
|
||||||
|
const value = parseInt(e.target.value, 10);
|
||||||
|
if (value >= 1 && value <= 1000) {
|
||||||
|
updateTarget(row.original.targetId, {
|
||||||
|
...row.original,
|
||||||
|
priority: value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "path",
|
accessorKey: "path",
|
||||||
header: t("matchPath"),
|
header: t("matchPath"),
|
||||||
|
|||||||
Reference in New Issue
Block a user