diff --git a/apps/dokploy/server/api/routers/mariadb.ts b/apps/dokploy/server/api/routers/mariadb.ts index 7d4bd2e50..b52b737a5 100644 --- a/apps/dokploy/server/api/routers/mariadb.ts +++ b/apps/dokploy/server/api/routers/mariadb.ts @@ -1,5 +1,6 @@ import { addNewService, + checkPortInUse, checkServiceAccess, createMariadb, createMount, @@ -172,6 +173,20 @@ export const mariadbRouter = createTRPCRouter({ message: "You are not authorized to save this external port", }); } + + if (input.externalPort) { + const portCheck = await checkPortInUse( + input.externalPort, + mongo.serverId || undefined, + ); + if (portCheck.isInUse) { + throw new TRPCError({ + code: "CONFLICT", + message: `Port ${input.externalPort} is already in use by ${portCheck.conflictingContainer}`, + }); + } + } + await updateMariadbById(input.mariadbId, { externalPort: input.externalPort, }); diff --git a/apps/dokploy/server/api/routers/mongo.ts b/apps/dokploy/server/api/routers/mongo.ts index ae0fa4741..661c808db 100644 --- a/apps/dokploy/server/api/routers/mongo.ts +++ b/apps/dokploy/server/api/routers/mongo.ts @@ -1,5 +1,6 @@ import { addNewService, + checkPortInUse, checkServiceAccess, createMongo, createMount, @@ -189,6 +190,20 @@ export const mongoRouter = createTRPCRouter({ message: "You are not authorized to save this external port", }); } + + if (input.externalPort) { + const portCheck = await checkPortInUse( + input.externalPort, + mongo.serverId || undefined, + ); + if (portCheck.isInUse) { + throw new TRPCError({ + code: "CONFLICT", + message: `Port ${input.externalPort} is already in use by ${portCheck.conflictingContainer}`, + }); + } + } + await updateMongoById(input.mongoId, { externalPort: input.externalPort, }); diff --git a/apps/dokploy/server/api/routers/mysql.ts b/apps/dokploy/server/api/routers/mysql.ts index 5204fedc8..ffbf9c593 100644 --- a/apps/dokploy/server/api/routers/mysql.ts +++ b/apps/dokploy/server/api/routers/mysql.ts @@ -1,5 +1,6 @@ import { addNewService, + checkPortInUse, checkServiceAccess, createMount, createMysql, @@ -187,6 +188,20 @@ export const mysqlRouter = createTRPCRouter({ message: "You are not authorized to save this external port", }); } + + if (input.externalPort) { + const portCheck = await checkPortInUse( + input.externalPort, + mongo.serverId || undefined, + ); + if (portCheck.isInUse) { + throw new TRPCError({ + code: "CONFLICT", + message: `Port ${input.externalPort} is already in use by ${portCheck.conflictingContainer}`, + }); + } + } + await updateMySqlById(input.mysqlId, { externalPort: input.externalPort, }); diff --git a/apps/dokploy/server/api/routers/postgres.ts b/apps/dokploy/server/api/routers/postgres.ts index e1718bff1..97db0b878 100644 --- a/apps/dokploy/server/api/routers/postgres.ts +++ b/apps/dokploy/server/api/routers/postgres.ts @@ -1,5 +1,6 @@ import { addNewService, + checkPortInUse, checkServiceAccess, createMount, createPostgres, @@ -192,6 +193,20 @@ export const postgresRouter = createTRPCRouter({ message: "You are not authorized to save this external port", }); } + + if (input.externalPort) { + const portCheck = await checkPortInUse( + input.externalPort, + postgres.serverId || undefined, + ); + if (portCheck.isInUse) { + throw new TRPCError({ + code: "CONFLICT", + message: `Port ${input.externalPort} is already in use by ${portCheck.conflictingContainer}`, + }); + } + } + await updatePostgresById(input.postgresId, { externalPort: input.externalPort, }); diff --git a/apps/dokploy/server/api/routers/redis.ts b/apps/dokploy/server/api/routers/redis.ts index d377b1707..0f09ae0dd 100644 --- a/apps/dokploy/server/api/routers/redis.ts +++ b/apps/dokploy/server/api/routers/redis.ts @@ -1,5 +1,6 @@ import { addNewService, + checkPortInUse, checkServiceAccess, createMount, createRedis, @@ -211,6 +212,20 @@ export const redisRouter = createTRPCRouter({ message: "You are not authorized to save this external port", }); } + + if (input.externalPort) { + const portCheck = await checkPortInUse( + input.externalPort, + mongo.serverId || undefined, + ); + if (portCheck.isInUse) { + throw new TRPCError({ + code: "CONFLICT", + message: `Port ${input.externalPort} is already in use by ${portCheck.conflictingContainer}`, + }); + } + } + await updateRedisById(input.redisId, { externalPort: input.externalPort, });