From 6a5fb8faff40a032f583ffd94dffecd4a6781b38 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Mon, 30 Sep 2024 15:00:32 -0600 Subject: [PATCH] fix(multi-server): show the servers ip instead of the main ip #502 --- .../mariadb/general/show-external-mariadb-credentials.tsx | 5 +++-- .../mongo/general/show-external-mongo-credentials.tsx | 6 +++--- .../mysql/general/show-external-mysql-credentials.tsx | 6 +++--- .../postgres/general/show-external-postgres-credentials.tsx | 6 +++--- .../redis/general/show-external-redis-credentials.tsx | 5 +++-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/apps/dokploy/components/dashboard/mariadb/general/show-external-mariadb-credentials.tsx b/apps/dokploy/components/dashboard/mariadb/general/show-external-mariadb-credentials.tsx index a908de077..c06cacaa8 100644 --- a/apps/dokploy/components/dashboard/mariadb/general/show-external-mariadb-credentials.tsx +++ b/apps/dokploy/components/dashboard/mariadb/general/show-external-mariadb-credentials.tsx @@ -48,6 +48,7 @@ export const ShowExternalMariadbCredentials = ({ mariadbId }: Props) => { const { data, refetch } = api.mariadb.one.useQuery({ mariadbId }); const { mutateAsync, isLoading } = api.mariadb.saveExternalPort.useMutation(); const [connectionUrl, setConnectionUrl] = useState(""); + const getIp = data?.server?.ipAddress || ip; const form = useForm({ defaultValues: {}, resolver: zodResolver(DockerProviderSchema), @@ -79,7 +80,7 @@ export const ShowExternalMariadbCredentials = ({ mariadbId }: Props) => { const buildConnectionUrl = () => { const port = form.watch("externalPort") || data?.externalPort; - return `mariadb://${data?.databaseUser}:${data?.databasePassword}@${ip}:${port}/${data?.databaseName}`; + return `mariadb://${data?.databaseUser}:${data?.databasePassword}@${getIp}:${port}/${data?.databaseName}`; }; setConnectionUrl(buildConnectionUrl()); @@ -90,7 +91,7 @@ export const ShowExternalMariadbCredentials = ({ mariadbId }: Props) => { form, data?.databaseName, data?.databaseUser, - ip, + getIp, ]); return ( <> diff --git a/apps/dokploy/components/dashboard/mongo/general/show-external-mongo-credentials.tsx b/apps/dokploy/components/dashboard/mongo/general/show-external-mongo-credentials.tsx index 36d04c9cb..7cfab289d 100644 --- a/apps/dokploy/components/dashboard/mongo/general/show-external-mongo-credentials.tsx +++ b/apps/dokploy/components/dashboard/mongo/general/show-external-mongo-credentials.tsx @@ -48,7 +48,7 @@ export const ShowExternalMongoCredentials = ({ mongoId }: Props) => { const { data, refetch } = api.mongo.one.useQuery({ mongoId }); const { mutateAsync, isLoading } = api.mongo.saveExternalPort.useMutation(); const [connectionUrl, setConnectionUrl] = useState(""); - + const getIp = data?.server?.ipAddress || ip; const form = useForm({ defaultValues: {}, resolver: zodResolver(DockerProviderSchema), @@ -80,7 +80,7 @@ export const ShowExternalMongoCredentials = ({ mongoId }: Props) => { const buildConnectionUrl = () => { const port = form.watch("externalPort") || data?.externalPort; - return `mongodb://${data?.databaseUser}:${data?.databasePassword}@${ip}:${port}`; + return `mongodb://${data?.databaseUser}:${data?.databasePassword}@${getIp}:${port}`; }; setConnectionUrl(buildConnectionUrl()); @@ -90,7 +90,7 @@ export const ShowExternalMongoCredentials = ({ mongoId }: Props) => { data?.databasePassword, form, data?.databaseUser, - ip, + getIp, ]); return ( diff --git a/apps/dokploy/components/dashboard/mysql/general/show-external-mysql-credentials.tsx b/apps/dokploy/components/dashboard/mysql/general/show-external-mysql-credentials.tsx index 18c1adafe..009c8c3a5 100644 --- a/apps/dokploy/components/dashboard/mysql/general/show-external-mysql-credentials.tsx +++ b/apps/dokploy/components/dashboard/mysql/general/show-external-mysql-credentials.tsx @@ -48,7 +48,7 @@ export const ShowExternalMysqlCredentials = ({ mysqlId }: Props) => { const { data, refetch } = api.mysql.one.useQuery({ mysqlId }); const { mutateAsync, isLoading } = api.mysql.saveExternalPort.useMutation(); const [connectionUrl, setConnectionUrl] = useState(""); - + const getIp = data?.server?.ipAddress || ip; const form = useForm({ defaultValues: {}, resolver: zodResolver(DockerProviderSchema), @@ -80,7 +80,7 @@ export const ShowExternalMysqlCredentials = ({ mysqlId }: Props) => { const buildConnectionUrl = () => { const port = form.watch("externalPort") || data?.externalPort; - return `mysql://${data?.databaseUser}:${data?.databasePassword}@${ip}:${port}/${data?.databaseName}`; + return `mysql://${data?.databaseUser}:${data?.databasePassword}@${getIp}:${port}/${data?.databaseName}`; }; setConnectionUrl(buildConnectionUrl()); @@ -91,7 +91,7 @@ export const ShowExternalMysqlCredentials = ({ mysqlId }: Props) => { data?.databaseName, data?.databaseUser, form, - ip, + getIp, ]); return ( <> diff --git a/apps/dokploy/components/dashboard/postgres/general/show-external-postgres-credentials.tsx b/apps/dokploy/components/dashboard/postgres/general/show-external-postgres-credentials.tsx index 28a96eb24..e1b4369a6 100644 --- a/apps/dokploy/components/dashboard/postgres/general/show-external-postgres-credentials.tsx +++ b/apps/dokploy/components/dashboard/postgres/general/show-external-postgres-credentials.tsx @@ -48,6 +48,7 @@ export const ShowExternalPostgresCredentials = ({ postgresId }: Props) => { const { data, refetch } = api.postgres.one.useQuery({ postgresId }); const { mutateAsync, isLoading } = api.postgres.saveExternalPort.useMutation(); + const getIp = data?.server?.ipAddress || ip; const [connectionUrl, setConnectionUrl] = useState(""); const form = useForm({ @@ -79,10 +80,9 @@ export const ShowExternalPostgresCredentials = ({ postgresId }: Props) => { useEffect(() => { const buildConnectionUrl = () => { - const hostname = window.location.hostname; const port = form.watch("externalPort") || data?.externalPort; - return `postgresql://${data?.databaseUser}:${data?.databasePassword}@${ip}:${port}/${data?.databaseName}`; + return `postgresql://${data?.databaseUser}:${data?.databasePassword}@${getIp}:${port}/${data?.databaseName}`; }; setConnectionUrl(buildConnectionUrl()); @@ -92,7 +92,7 @@ export const ShowExternalPostgresCredentials = ({ postgresId }: Props) => { data?.databasePassword, form, data?.databaseName, - ip, + getIp, ]); return ( diff --git a/apps/dokploy/components/dashboard/redis/general/show-external-redis-credentials.tsx b/apps/dokploy/components/dashboard/redis/general/show-external-redis-credentials.tsx index b88328417..bcb26267a 100644 --- a/apps/dokploy/components/dashboard/redis/general/show-external-redis-credentials.tsx +++ b/apps/dokploy/components/dashboard/redis/general/show-external-redis-credentials.tsx @@ -48,6 +48,7 @@ export const ShowExternalRedisCredentials = ({ redisId }: Props) => { const { data, refetch } = api.redis.one.useQuery({ redisId }); const { mutateAsync, isLoading } = api.redis.saveExternalPort.useMutation(); const [connectionUrl, setConnectionUrl] = useState(""); + const getIp = data?.server?.ipAddress || ip; const form = useForm({ defaultValues: {}, @@ -81,11 +82,11 @@ export const ShowExternalRedisCredentials = ({ redisId }: Props) => { const hostname = window.location.hostname; const port = form.watch("externalPort") || data?.externalPort; - return `redis://default:${data?.databasePassword}@${ip}:${port}`; + return `redis://default:${data?.databasePassword}@${getIp}:${port}`; }; setConnectionUrl(buildConnectionUrl()); - }, [data?.appName, data?.externalPort, data?.databasePassword, form, ip]); + }, [data?.appName, data?.externalPort, data?.databasePassword, form, getIp]); return ( <>