mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-13 14:21:40 +02:00
ensure subdomain is null if is base domain
This commit is contained in:
parent
f1291d4d7d
commit
a3be0d4655
3 changed files with 51 additions and 30 deletions
|
@ -35,8 +35,8 @@ const createHttpResourceSchema = z
|
||||||
name: z.string().min(1).max(255),
|
name: z.string().min(1).max(255),
|
||||||
subdomain: z
|
subdomain: z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.nullable()
|
||||||
.transform((val) => val?.toLowerCase()),
|
.optional(),
|
||||||
siteId: z.number(),
|
siteId: z.number(),
|
||||||
http: z.boolean(),
|
http: z.boolean(),
|
||||||
protocol: z.enum(["tcp", "udp"]),
|
protocol: z.enum(["tcp", "udp"]),
|
||||||
|
@ -201,7 +201,8 @@ async function createHttpResource(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { name, subdomain, domainId } = parsedBody.data;
|
const { name, domainId } = parsedBody.data;
|
||||||
|
let subdomain = parsedBody.data.subdomain;
|
||||||
|
|
||||||
const [domainRes] = await db
|
const [domainRes] = await db
|
||||||
.select()
|
.select()
|
||||||
|
@ -274,6 +275,10 @@ async function createHttpResource(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fullDomain === domainRes.domains.baseDomain) {
|
||||||
|
subdomain = null;
|
||||||
|
}
|
||||||
|
|
||||||
fullDomain = fullDomain.toLowerCase();
|
fullDomain = fullDomain.toLowerCase();
|
||||||
|
|
||||||
logger.debug(`Full domain: ${fullDomain}`);
|
logger.debug(`Full domain: ${fullDomain}`);
|
||||||
|
|
|
@ -35,8 +35,8 @@ const updateHttpResourceBodySchema = z
|
||||||
.object({
|
.object({
|
||||||
name: z.string().min(1).max(255).optional(),
|
name: z.string().min(1).max(255).optional(),
|
||||||
subdomain: subdomainSchema
|
subdomain: subdomainSchema
|
||||||
.optional()
|
.nullable()
|
||||||
.transform((val) => val?.toLowerCase()),
|
.optional(),
|
||||||
ssl: z.boolean().optional(),
|
ssl: z.boolean().optional(),
|
||||||
sso: z.boolean().optional(),
|
sso: z.boolean().optional(),
|
||||||
blockAccess: z.boolean().optional(),
|
blockAccess: z.boolean().optional(),
|
||||||
|
@ -286,7 +286,7 @@ async function updateHttpResource(
|
||||||
} else if (domainRes.domains.type == "cname") {
|
} else if (domainRes.domains.type == "cname") {
|
||||||
fullDomain = domainRes.domains.baseDomain;
|
fullDomain = domainRes.domains.baseDomain;
|
||||||
} else if (domainRes.domains.type == "wildcard") {
|
} else if (domainRes.domains.type == "wildcard") {
|
||||||
if (updateData.subdomain) {
|
if (updateData.subdomain !== undefined) {
|
||||||
// the subdomain cant have a dot in it
|
// the subdomain cant have a dot in it
|
||||||
const parsedSubdomain = subdomainSchema.safeParse(updateData.subdomain);
|
const parsedSubdomain = subdomainSchema.safeParse(updateData.subdomain);
|
||||||
if (!parsedSubdomain.success) {
|
if (!parsedSubdomain.success) {
|
||||||
|
@ -341,11 +341,15 @@ async function updateHttpResource(
|
||||||
.set({ fullDomain })
|
.set({ fullDomain })
|
||||||
.where(eq(resources.resourceId, resource.resourceId));
|
.where(eq(resources.resourceId, resource.resourceId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fullDomain === domainRes.domains.baseDomain) {
|
||||||
|
updateData.subdomain = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedResource = await db
|
const updatedResource = await db
|
||||||
.update(resources)
|
.update(resources)
|
||||||
.set(updateData)
|
.set({...updateData, })
|
||||||
.where(eq(resources.resourceId, resource.resourceId))
|
.where(eq(resources.resourceId, resource.resourceId))
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
|
|
|
@ -118,8 +118,7 @@ export default function GeneralForm() {
|
||||||
fullDomain: string;
|
fullDomain: string;
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
|
|
||||||
const GeneralFormSchema = z
|
const GeneralFormSchema = z.object({
|
||||||
.object({
|
|
||||||
enabled: z.boolean(),
|
enabled: z.boolean(),
|
||||||
subdomain: z.string().optional(),
|
subdomain: z.string().optional(),
|
||||||
name: z.string().min(1).max(255),
|
name: z.string().min(1).max(255),
|
||||||
|
@ -197,7 +196,7 @@ export default function GeneralForm() {
|
||||||
enabled: data.enabled,
|
enabled: data.enabled,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
subdomain: data.subdomain,
|
subdomain: data.subdomain,
|
||||||
domainId: data.domainId,
|
domainId: data.domainId
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
|
@ -299,11 +298,9 @@ export default function GeneralForm() {
|
||||||
defaultChecked={
|
defaultChecked={
|
||||||
resource.enabled
|
resource.enabled
|
||||||
}
|
}
|
||||||
label={
|
label={t(
|
||||||
t(
|
|
||||||
"resourceEnable"
|
"resourceEnable"
|
||||||
)
|
)}
|
||||||
}
|
|
||||||
onCheckedChange={(
|
onCheckedChange={(
|
||||||
val
|
val
|
||||||
) =>
|
) =>
|
||||||
|
@ -438,7 +435,10 @@ export default function GeneralForm() {
|
||||||
</Button>
|
</Button>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent className="w-full p-0" align="start">
|
<PopoverContent
|
||||||
|
className="w-full p-0"
|
||||||
|
align="start"
|
||||||
|
>
|
||||||
<Command>
|
<Command>
|
||||||
<CommandInput
|
<CommandInput
|
||||||
placeholder={t(
|
placeholder={t(
|
||||||
|
@ -539,14 +539,26 @@ export default function GeneralForm() {
|
||||||
<CredenzaClose asChild>
|
<CredenzaClose asChild>
|
||||||
<Button variant="outline">{t("cancel")}</Button>
|
<Button variant="outline">{t("cancel")}</Button>
|
||||||
</CredenzaClose>
|
</CredenzaClose>
|
||||||
<Button onClick={() => {
|
<Button
|
||||||
|
onClick={() => {
|
||||||
if (selectedDomain) {
|
if (selectedDomain) {
|
||||||
setResourceFullDomain(selectedDomain.fullDomain);
|
setResourceFullDomain(
|
||||||
form.setValue("domainId", selectedDomain.domainId);
|
selectedDomain.fullDomain
|
||||||
form.setValue("subdomain", selectedDomain.subdomain);
|
);
|
||||||
|
form.setValue(
|
||||||
|
"domainId",
|
||||||
|
selectedDomain.domainId
|
||||||
|
);
|
||||||
|
form.setValue(
|
||||||
|
"subdomain",
|
||||||
|
selectedDomain.subdomain
|
||||||
|
);
|
||||||
setEditDomainOpen(false);
|
setEditDomainOpen(false);
|
||||||
}
|
}
|
||||||
}}>Select Domain</Button>
|
}}
|
||||||
|
>
|
||||||
|
Select Domain
|
||||||
|
</Button>
|
||||||
</CredenzaFooter>
|
</CredenzaFooter>
|
||||||
</CredenzaContent>
|
</CredenzaContent>
|
||||||
</Credenza>
|
</Credenza>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue