backend setup

This commit is contained in:
Owen
2025-10-04 21:25:31 -07:00
committed by Pallavi Kumari
parent b47fc9f901
commit ff2bcfb0e7
7 changed files with 56 additions and 9 deletions

View File

@@ -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", {

View File

@@ -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", {

View File

@@ -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).default(100)
}) })
.strict(); .strict();

View File

@@ -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))

View File

@@ -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).default(100)
}) })
.strict() .strict()
.refine((data) => Object.keys(data).length > 0, { .refine((data) => Object.keys(data).length > 0, {

View File

@@ -489,6 +489,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,
@@ -682,21 +683,20 @@ export default function ReverseProxyTargets(props: {
</div> </div>
), ),
cell: ({ row }) => { cell: ({ row }) => {
const targetIndex = targets.findIndex(t => t.targetId === row.original.targetId);
return ( return (
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<Input <Input
type="number" type="number"
min="1" min="1"
max="1000" max="1000"
defaultValue={100 + targetIndex + 1} defaultValue={row.original.priority || 100}
className="w-20" className="w-20"
onBlur={(e) => { onBlur={(e) => {
const value = parseInt(e.target.value, 10); const value = parseInt(e.target.value, 10);
if (value >= 1 && value <= 1000) { if (value >= 1 && value <= 1000) {
updateTarget(row.original.targetId, { updateTarget(row.original.targetId, {
...row.original, ...row.original,
//priority: value priority: value
}); });
} }
}} }}

View File

@@ -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";
@@ -341,6 +342,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,
@@ -598,6 +600,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. Use this to ensure specific paths like /api/v1 are checked before catch-all routes like /</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"),