From 2dcc94cd14be3b9ee350b4b534d1203e5b9dee3b Mon Sep 17 00:00:00 2001 From: miloschwartz Date: Thu, 4 Dec 2025 22:03:37 -0500 Subject: [PATCH] fix hc port NaN issue --- messages/en-US.json | 7 ++- .../resources/proxy/[niceId]/proxy/page.tsx | 3 +- src/components/HealthCheckDialog.tsx | 63 +++++++++++++------ 3 files changed, 49 insertions(+), 24 deletions(-) diff --git a/messages/en-US.json b/messages/en-US.json index 3a6eff5a..6565143c 100644 --- a/messages/en-US.json +++ b/messages/en-US.json @@ -1510,14 +1510,15 @@ "enableHealthChecksDescription": "Monitor the health of this target. You can monitor a different endpoint than the target if required.", "healthScheme": "Method", "healthSelectScheme": "Select Method", + "healthCheckPortInvalid": "Health check port must be between 1 and 65535", "healthCheckPath": "Path", "healthHostname": "IP / Host", "healthPort": "Port", "healthCheckPathDescription": "The path to check for health status.", - "healthyIntervalSeconds": "Healthy Interval", - "unhealthyIntervalSeconds": "Unhealthy Interval", + "healthyIntervalSeconds": "Healthy Interval (sec)", + "unhealthyIntervalSeconds": "Unhealthy Interval (sec)", "IntervalSeconds": "Healthy Interval", - "timeoutSeconds": "Timeout", + "timeoutSeconds": "Timeout (sec)", "timeIsInSeconds": "Time is in seconds", "retryAttempts": "Retry Attempts", "expectedResponseCodes": "Expected Response Codes", diff --git a/src/app/[orgId]/settings/resources/proxy/[niceId]/proxy/page.tsx b/src/app/[orgId]/settings/resources/proxy/[niceId]/proxy/page.tsx index 2efcaac8..981665e2 100644 --- a/src/app/[orgId]/settings/resources/proxy/[niceId]/proxy/page.tsx +++ b/src/app/[orgId]/settings/resources/proxy/[niceId]/proxy/page.tsx @@ -691,6 +691,7 @@ export default function ReverseProxyTargets(props: { target.port <= 0 || isNaN(target.port) ); + console.log(targetsWithInvalidFields); if (targetsWithInvalidFields.length > 0) { toast({ variant: "destructive", @@ -1833,9 +1834,7 @@ export default function ReverseProxyTargets(props: { 30 }} onChanges={async (config) => { - console.log("here"); if (selectedTargetForHealthCheck) { - console.log(config); updateTargetHealthCheck( selectedTargetForHealthCheck.targetId, config diff --git a/src/components/HealthCheckDialog.tsx b/src/components/HealthCheckDialog.tsx index be5e5d45..1bdef85e 100644 --- a/src/components/HealthCheckDialog.tsx +++ b/src/components/HealthCheckDialog.tsx @@ -80,17 +80,33 @@ export default function HealthCheckDialog({ hcMethod: z .string() .min(1, { message: t("healthCheckMethodRequired") }), - hcInterval: z.int() + hcInterval: z + .int() .positive() .min(5, { message: t("healthCheckIntervalMin") }), - hcTimeout: z.int() + hcTimeout: z + .int() .positive() .min(1, { message: t("healthCheckTimeoutMin") }), hcStatus: z.int().positive().min(100).optional().nullable(), - hcHeaders: z.array(z.object({ name: z.string(), value: z.string() })).nullable().optional(), + hcHeaders: z + .array(z.object({ name: z.string(), value: z.string() })) + .nullable() + .optional(), hcScheme: z.string().optional(), hcHostname: z.string(), - hcPort: z.number().positive().gt(0).lte(65535), + hcPort: z + .string() + .min(1, { message: t("healthCheckPortInvalid") }) + .refine( + (val) => { + const port = parseInt(val); + return port > 0 && port <= 65535; + }, + { + message: t("healthCheckPortInvalid") + } + ), hcFollowRedirects: z.boolean(), hcMode: z.string(), hcUnhealthyInterval: z.int().positive().min(5) @@ -126,7 +142,9 @@ export default function HealthCheckDialog({ hcHeaders: initialConfig?.hcHeaders, hcScheme: getDefaultScheme(), hcHostname: initialConfig?.hcHostname, - hcPort: initialConfig?.hcPort, + hcPort: initialConfig?.hcPort + ? initialConfig.hcPort.toString() + : "", hcFollowRedirects: initialConfig?.hcFollowRedirects, hcMode: initialConfig?.hcMode, hcUnhealthyInterval: initialConfig?.hcUnhealthyInterval @@ -139,10 +157,15 @@ export default function HealthCheckDialog({ try { const currentValues = form.getValues(); const updatedValues = { ...currentValues, [fieldName]: value }; - await onChanges({ + + // Convert hcPort from string to number before passing to parent + const configToSend: HealthCheckConfig = { ...updatedValues, + hcPort: parseInt(updatedValues.hcPort), hcStatus: updatedValues.hcStatus || null - }); + }; + + await onChanges(configToSend); } catch (error) { toast({ title: t("healthCheckError"), @@ -210,14 +233,20 @@ export default function HealthCheckDialog({ {t("healthScheme")}