From dc2d15fd9c34860f8d73d73fdadd31fd426415fa Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 27 Oct 2022 20:05:02 +0000 Subject: [PATCH] fix --- apps/api/src/lib/common.ts | 5 ++-- .../src/routes/api/v1/services/handlers.ts | 24 ++++++++++--------- apps/ui/src/routes/services/[id]/index.svelte | 13 +++++----- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts index 4a4de8be7..8c1658630 100644 --- a/apps/api/src/lib/common.ts +++ b/apps/api/src/lib/common.ts @@ -281,9 +281,7 @@ export async function isDomainConfigured({ where: { OR: [ { fqdn: { endsWith: `//${nakedDomain}` } }, - { fqdn: { endsWith: `//www.${nakedDomain}` } }, - { minio: { apiFqdn: { endsWith: `//${nakedDomain}` } } }, - { minio: { apiFqdn: { endsWith: `//www.${nakedDomain}` } } } + { fqdn: { endsWith: `//www.${nakedDomain}` } } ], id: { not: checkOwn ? undefined : id }, destinationDocker: { @@ -303,6 +301,7 @@ export async function isDomainConfigured({ }, select: { fqdn: true } }); + console.log({foundApp, foundService}) return !!(foundApp || foundService || coolifyFqdn); } diff --git a/apps/api/src/routes/api/v1/services/handlers.ts b/apps/api/src/routes/api/v1/services/handlers.ts index b4f43ea55..52f52c7f2 100644 --- a/apps/api/src/routes/api/v1/services/handlers.ts +++ b/apps/api/src/routes/api/v1/services/handlers.ts @@ -436,10 +436,17 @@ export async function checkServiceDomain(request: FastifyRequest) { try { const { id } = request.params; - let { fqdn, exposePort, forceSave, otherFqdns, dualCerts } = request.body; - + let { fqdn, exposePort, forceSave, dualCerts } = request.body; + const otherFqdns = await prisma.serviceSetting.findMany({where: { variableName: {startsWith: '$$coolify_fqdn'}}}) + let domainsList = [] if (fqdn) fqdn = fqdn.toLowerCase(); - if (otherFqdns && otherFqdns.length > 0) otherFqdns = otherFqdns.map((f) => f.toLowerCase()); + if (otherFqdns && otherFqdns.length > 0) { + domainsList = otherFqdns.filter((f) => { + if(f.serviceId !== id) { + return f + } + }); + } if (exposePort) exposePort = Number(exposePort); const { destinationDocker: { remoteIpAddress, remoteEngine, engine }, exposePort: configuredPort } = await prisma.service.findUnique({ where: { id }, include: { destinationDocker: true } }) @@ -449,13 +456,8 @@ export async function checkService(request: FastifyRequest) { if (found) { throw { status: 500, message: `Domain ${getDomain(fqdn).replace('www.', '')} is already in use!` } } - if (otherFqdns && otherFqdns.length > 0) { - for (const ofqdn of otherFqdns) { - found = await isDomainConfigured({ id, fqdn: ofqdn, remoteIpAddress }); - if (found) { - throw { status: 500, message: `Domain ${getDomain(ofqdn).replace('www.', '')} is already in use!` } - } - } + if (domainsList.find(d => getDomain(d.value) === getDomain(fqdn))) { + throw { status: 500, message: `Domain ${getDomain(fqdn).replace('www.', '')} is already in use!` } } if (exposePort) await checkExposedPort({ id, configuredPort, exposePort, engine, remoteEngine, remoteIpAddress }) if (isDNSCheckEnabled && !isDev && !forceSave) { @@ -484,7 +486,7 @@ export async function saveService(request: FastifyRequest, reply: F } const templates = await getTemplates() const service = await prisma.service.findUnique({ where: { id } }) - const foundTemplate = templates.find(t => fixType(t.name) === service.type) + const foundTemplate = templates.find(t => fixType(t.name) === fixType(service.type)) for (const setting of serviceSetting) { let { id: settingId, name, value, changed = false, isNew = false, variableName } = setting if (changed) { diff --git a/apps/ui/src/routes/services/[id]/index.svelte b/apps/ui/src/routes/services/[id]/index.svelte index 69a066c54..2109f0d66 100644 --- a/apps/ui/src/routes/services/[id]/index.svelte +++ b/apps/ui/src/routes/services/[id]/index.svelte @@ -78,13 +78,12 @@ if (loading.save) return; loading.save = true; try { - // await post(`/services/${id}/check`, { - // fqdn: service.fqdn, - // forceSave, - // dualCerts, - // otherFqdns: service.minio?.apiFqdn ? [service.minio?.apiFqdn] : [], - // exposePort: service.exposePort - // }); + await post(`/services/${id}/check`, { + fqdn: service.fqdn, + forceSave, + dualCerts, + exposePort: service.exposePort + }); const formData = new FormData(e.target); if (formData) service = await saveForm(formData, service); setLocation(service);