fix update resource without subdomain

This commit is contained in:
Milo Schwartz 2025-02-05 21:32:49 -05:00
parent c51f1cb6a2
commit 3fa7132534
No known key found for this signature in database
2 changed files with 20 additions and 14 deletions

View file

@ -175,10 +175,10 @@ export async function updateResource(
); );
} }
let fullDomain = ""; let fullDomain: string | undefined;
if (updateData.isBaseDomain) { if (updateData.isBaseDomain) {
fullDomain = org.domain; fullDomain = org.domain;
} else { } else if (updateData.subdomain) {
fullDomain = `${updateData.subdomain}.${org.domain}`; fullDomain = `${updateData.subdomain}.${org.domain}`;
} }
@ -187,18 +187,24 @@ export async function updateResource(
...(fullDomain && { fullDomain }) ...(fullDomain && { fullDomain })
}; };
const [existingDomain] = await db if (
.select() fullDomain &&
.from(resources) (updatePayload.subdomain !== undefined ||
.where(eq(resources.fullDomain, fullDomain)); updatePayload.isBaseDomain !== undefined)
) {
const [existingDomain] = await db
.select()
.from(resources)
.where(eq(resources.fullDomain, fullDomain));
if (existingDomain && existingDomain.resourceId !== resourceId) { if (existingDomain && existingDomain.resourceId !== resourceId) {
return next( return next(
createHttpError( createHttpError(
HttpCode.CONFLICT, HttpCode.CONFLICT,
"Resource with that domain already exists" "Resource with that domain already exists"
) )
); );
}
} }
const updatedResource = await db const updatedResource = await db

View file

@ -42,7 +42,7 @@ export const ResourcesSplashCard = () => {
Resources Resources
</h3> </h3>
<p className="text-sm"> <p className="text-sm">
Resources are proxies to applications running on your private network. Create a resource for any HTTP or HTTPS app on your private network. Resources are proxies to applications running on your private network. Create a resource for any HTTP/HTTPS or raw TCP/UDP service on your private network.
Each resource must be connected to a site to enable private, secure connectivity through an encrypted WireGuard tunnel. Each resource must be connected to a site to enable private, secure connectivity through an encrypted WireGuard tunnel.
</p> </p>
<ul className="text-sm text-muted-foreground space-y-2"> <ul className="text-sm text-muted-foreground space-y-2">