From f36de7b2f542d7f6fd0e9742b59ab346b3d9cce7 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 20 Jul 2024 15:23:44 -0600 Subject: [PATCH] refactor(databases): show ip in external connection instead of hostname --- .../mariadb/general/show-external-mariadb-credentials.tsx | 4 ++-- .../mongo/general/show-external-mongo-credentials.tsx | 4 ++-- .../mysql/general/show-external-mysql-credentials.tsx | 4 ++-- .../postgres/general/show-external-postgres-credentials.tsx | 3 ++- .../redis/general/show-external-redis-credentials.tsx | 3 ++- server/api/routers/settings.ts | 4 ++++ 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/components/dashboard/mariadb/general/show-external-mariadb-credentials.tsx b/components/dashboard/mariadb/general/show-external-mariadb-credentials.tsx index 176ab7d0..b4ed7dc4 100644 --- a/components/dashboard/mariadb/general/show-external-mariadb-credentials.tsx +++ b/components/dashboard/mariadb/general/show-external-mariadb-credentials.tsx @@ -44,6 +44,7 @@ interface Props { mariadbId: string; } export const ShowExternalMariadbCredentials = ({ mariadbId }: Props) => { + const { data: ip } = api.settings.getIp.useQuery(); const { data, refetch } = api.mariadb.one.useQuery({ mariadbId }); const { mutateAsync, isLoading } = api.mariadb.saveExternalPort.useMutation(); const [connectionUrl, setConnectionUrl] = useState(""); @@ -76,10 +77,9 @@ export const ShowExternalMariadbCredentials = ({ mariadbId }: Props) => { useEffect(() => { const buildConnectionUrl = () => { - const hostname = window.location.hostname; const port = form.watch("externalPort") || data?.externalPort; - return `mariadb://${data?.databaseUser}:${data?.databasePassword}@${hostname}:${port}/${data?.databaseName}`; + return `mariadb://${data?.databaseUser}:${data?.databasePassword}@${ip}:${port}/${data?.databaseName}`; }; setConnectionUrl(buildConnectionUrl()); diff --git a/components/dashboard/mongo/general/show-external-mongo-credentials.tsx b/components/dashboard/mongo/general/show-external-mongo-credentials.tsx index c8a3fa23..52b584fb 100644 --- a/components/dashboard/mongo/general/show-external-mongo-credentials.tsx +++ b/components/dashboard/mongo/general/show-external-mongo-credentials.tsx @@ -44,6 +44,7 @@ interface Props { mongoId: string; } export const ShowExternalMongoCredentials = ({ mongoId }: Props) => { + const { data: ip } = api.settings.getIp.useQuery(); const { data, refetch } = api.mongo.one.useQuery({ mongoId }); const { mutateAsync, isLoading } = api.mongo.saveExternalPort.useMutation(); const [connectionUrl, setConnectionUrl] = useState(""); @@ -77,10 +78,9 @@ export const ShowExternalMongoCredentials = ({ mongoId }: Props) => { useEffect(() => { const buildConnectionUrl = () => { - const hostname = window.location.hostname; const port = form.watch("externalPort") || data?.externalPort; - return `mongodb://${data?.databaseUser}:${data?.databasePassword}@${hostname}:${port}`; + return `mongodb://${data?.databaseUser}:${data?.databasePassword}@${ip}:${port}`; }; setConnectionUrl(buildConnectionUrl()); diff --git a/components/dashboard/mysql/general/show-external-mysql-credentials.tsx b/components/dashboard/mysql/general/show-external-mysql-credentials.tsx index ce184a98..caaf8556 100644 --- a/components/dashboard/mysql/general/show-external-mysql-credentials.tsx +++ b/components/dashboard/mysql/general/show-external-mysql-credentials.tsx @@ -44,6 +44,7 @@ interface Props { mysqlId: string; } export const ShowExternalMysqlCredentials = ({ mysqlId }: Props) => { + const { data: ip } = api.settings.getIp.useQuery(); const { data, refetch } = api.mysql.one.useQuery({ mysqlId }); const { mutateAsync, isLoading } = api.mysql.saveExternalPort.useMutation(); const [connectionUrl, setConnectionUrl] = useState(""); @@ -77,10 +78,9 @@ export const ShowExternalMysqlCredentials = ({ mysqlId }: Props) => { useEffect(() => { const buildConnectionUrl = () => { - const hostname = window.location.hostname; const port = form.watch("externalPort") || data?.externalPort; - return `mysql://${data?.databaseUser}:${data?.databasePassword}@${hostname}:${port}/${data?.databaseName}`; + return `mysql://${data?.databaseUser}:${data?.databasePassword}@${ip}:${port}/${data?.databaseName}`; }; setConnectionUrl(buildConnectionUrl()); diff --git a/components/dashboard/postgres/general/show-external-postgres-credentials.tsx b/components/dashboard/postgres/general/show-external-postgres-credentials.tsx index edb128bf..d27022b7 100644 --- a/components/dashboard/postgres/general/show-external-postgres-credentials.tsx +++ b/components/dashboard/postgres/general/show-external-postgres-credentials.tsx @@ -44,6 +44,7 @@ interface Props { postgresId: string; } export const ShowExternalPostgresCredentials = ({ postgresId }: Props) => { + const { data: ip } = api.settings.getIp.useQuery(); const { data, refetch } = api.postgres.one.useQuery({ postgresId }); const { mutateAsync, isLoading } = api.postgres.saveExternalPort.useMutation(); @@ -81,7 +82,7 @@ export const ShowExternalPostgresCredentials = ({ postgresId }: Props) => { const hostname = window.location.hostname; const port = form.watch("externalPort") || data?.externalPort; - return `postgresql://${data?.databaseUser}:${data?.databasePassword}@${hostname}:${port}/${data?.databaseName}`; + return `postgresql://${data?.databaseUser}:${data?.databasePassword}@${ip}:${port}/${data?.databaseName}`; }; setConnectionUrl(buildConnectionUrl()); diff --git a/components/dashboard/redis/general/show-external-redis-credentials.tsx b/components/dashboard/redis/general/show-external-redis-credentials.tsx index ea62d77e..136f0ef4 100644 --- a/components/dashboard/redis/general/show-external-redis-credentials.tsx +++ b/components/dashboard/redis/general/show-external-redis-credentials.tsx @@ -44,6 +44,7 @@ interface Props { redisId: string; } export const ShowExternalRedisCredentials = ({ redisId }: Props) => { + const { data: ip } = api.settings.getIp.useQuery(); const { data, refetch } = api.redis.one.useQuery({ redisId }); const { mutateAsync, isLoading } = api.redis.saveExternalPort.useMutation(); const [connectionUrl, setConnectionUrl] = useState(""); @@ -80,7 +81,7 @@ export const ShowExternalRedisCredentials = ({ redisId }: Props) => { const hostname = window.location.hostname; const port = form.watch("externalPort") || data?.externalPort; - return `redis://default:${data?.databasePassword}@${hostname}:${port}`; + return `redis://default:${data?.databasePassword}@${ip}:${port}`; }; setConnectionUrl(buildConnectionUrl()); diff --git a/server/api/routers/settings.ts b/server/api/routers/settings.ts index 69f5655c..593db3a1 100644 --- a/server/api/routers/settings.ts +++ b/server/api/routers/settings.ts @@ -252,6 +252,10 @@ export const settingsRouter = createTRPCRouter({ } return readConfigInPath(input.path); }), + getIp: protectedProcedure.query(async () => { + const admin = await findAdmin(); + return admin.serverIp; + }), getOpenApiDocument: protectedProcedure.query( async ({ ctx }): Promise => {