fix: expose port checker

This commit is contained in:
Andras Bacsai
2022-07-22 08:57:11 +00:00
parent ac1991291d
commit df01139c41
4 changed files with 47 additions and 33 deletions

View File

@@ -994,8 +994,24 @@ export async function updatePasswordInDb(database, user, newPassword, isRoot) {
}
}
}
export async function getFreePort() {
export async function getExposedFreePort(id, exposePort) {
const { default: getPort } = await import('get-port');
const applicationUsed = await (
await prisma.application.findMany({
where: { exposePort: { not: null }, id: { not: id } },
select: { exposePort: true }
})
).map((a) => a.exposePort);
const serviceUsed = await (
await prisma.service.findMany({
where: { exposePort: { not: null }, id: { not: id } },
select: { exposePort: true }
})
).map((a) => a.exposePort);
const usedPorts = [...applicationUsed, ...serviceUsed];
return await getPort({ port: exposePort, exclude: usedPorts });
}
export async function getFreePublicPort() {
const { default: getPort, portNumbers } = await import('get-port');
const data = await prisma.setting.findFirst();
const { minPort, maxPort } = data;