diff --git a/server/routers/resource/createResource.ts b/server/routers/resource/createResource.ts index dfbb7617..8c80c90c 100644 --- a/server/routers/resource/createResource.ts +++ b/server/routers/resource/createResource.ts @@ -33,14 +33,11 @@ const createResourceParamsSchema = z const createHttpResourceSchema = z .object({ name: z.string().min(1).max(255), - subdomain: z - .string() - .nullable() - .optional(), + subdomain: z.string().nullable().optional(), siteId: z.number(), http: z.boolean(), protocol: z.enum(["tcp", "udp"]), - domainId: z.string(), + domainId: z.string() }) .strict() .refine( @@ -51,7 +48,7 @@ const createHttpResourceSchema = z return true; }, { message: "Invalid subdomain" } - ) + ); const createRawResourceSchema = z .object({ @@ -89,12 +86,7 @@ registry.registerPath({ body: { content: { "application/json": { - schema: - build == "oss" - ? createHttpResourceSchema.or( - createRawResourceSchema - ) - : createHttpResourceSchema + schema: createHttpResourceSchema.or(createRawResourceSchema) } } } @@ -157,7 +149,10 @@ export async function createResource( { siteId, orgId } ); } else { - if (!config.getRawConfig().flags?.allow_raw_resources && build == "oss") { + if ( + !config.getRawConfig().flags?.allow_raw_resources && + build == "oss" + ) { return next( createHttpError( HttpCode.BAD_REQUEST, diff --git a/server/routers/resource/updateResource.ts b/server/routers/resource/updateResource.ts index e99c6e8b..5cf68c2b 100644 --- a/server/routers/resource/updateResource.ts +++ b/server/routers/resource/updateResource.ts @@ -34,9 +34,7 @@ const updateResourceParamsSchema = z const updateHttpResourceBodySchema = z .object({ name: z.string().min(1).max(255).optional(), - subdomain: subdomainSchema - .nullable() - .optional(), + subdomain: subdomainSchema.nullable().optional(), ssl: z.boolean().optional(), sso: z.boolean().optional(), blockAccess: z.boolean().optional(), @@ -94,7 +92,7 @@ const updateRawResourceBodySchema = z proxyPort: z.number().int().min(1).max(65535).optional(), stickySession: z.boolean().optional(), enabled: z.boolean().optional(), - enableProxy: z.boolean().optional(), + enableProxy: z.boolean().optional() }) .strict() .refine((data) => Object.keys(data).length > 0, { @@ -122,12 +120,9 @@ registry.registerPath({ body: { content: { "application/json": { - schema: - build == "oss" - ? updateHttpResourceBodySchema.and( - updateRawResourceBodySchema - ) - : updateHttpResourceBodySchema + schema: updateHttpResourceBodySchema.and( + updateRawResourceBodySchema + ) } } } @@ -289,7 +284,9 @@ async function updateHttpResource( } else if (domainRes.domains.type == "wildcard") { if (updateData.subdomain !== undefined) { // the subdomain cant have a dot in it - const parsedSubdomain = subdomainSchema.safeParse(updateData.subdomain); + const parsedSubdomain = subdomainSchema.safeParse( + updateData.subdomain + ); if (!parsedSubdomain.success) { return next( createHttpError( @@ -342,7 +339,7 @@ async function updateHttpResource( const updatedResource = await db .update(resources) - .set({...updateData, }) + .set({ ...updateData }) .where(eq(resources.resourceId, resource.resourceId)) .returning(); diff --git a/src/app/[orgId]/settings/resources/[resourceId]/general/page.tsx b/src/app/[orgId]/settings/resources/[resourceId]/general/page.tsx index 68cc02cc..b4e14d64 100644 --- a/src/app/[orgId]/settings/resources/[resourceId]/general/page.tsx +++ b/src/app/[orgId]/settings/resources/[resourceId]/general/page.tsx @@ -221,7 +221,9 @@ export default function GeneralForm() { subdomain: data.subdomain, domainId: data.domainId, proxyPort: data.proxyPort, - enableProxy: data.enableProxy + ...(!resource.http && { + enableProxy: data.enableProxy + }) } ) .catch((e) => { @@ -249,7 +251,9 @@ export default function GeneralForm() { subdomain: data.subdomain, fullDomain: resource.fullDomain, proxyPort: data.proxyPort, - enableProxy: data.enableProxy + ...(!resource.http && { + enableProxy: data.enableProxy + }), }); router.refresh();