fix fqdn check

This commit is contained in:
Andras Bacsai 2022-10-28 09:15:03 +02:00
parent cdb25cd0e9
commit aa27aeafa1
5 changed files with 25 additions and 13 deletions

View File

@ -436,23 +436,17 @@ export async function checkServiceDomain(request: FastifyRequest<CheckServiceDom
export async function checkService(request: FastifyRequest<CheckService>) {
try {
const { id } = request.params;
let { fqdn, exposePort, forceSave, dualCerts } = request.body;
const otherFqdns = await prisma.serviceSetting.findMany({where: { variableName: {startsWith: '$$coolify_fqdn'}}})
let domainsList = []
let { fqdn, exposePort, forceSave, dualCerts, otherFqdn = false } = request.body;
const domainsList = await prisma.serviceSetting.findMany({ where: { variableName: { startsWith: '$$coolify_fqdn' } } })
if (fqdn) fqdn = fqdn.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 } })
const { isDNSCheckEnabled } = await prisma.setting.findFirst({});
let found = await isDomainConfigured({ id, fqdn, remoteIpAddress });
let found = await isDomainConfigured({ id, fqdn, remoteIpAddress, checkOwn: otherFqdn });
if (found) {
throw { status: 500, message: `Domain ${getDomain(fqdn).replace('www.', '')} is already in use!` }
}

View File

@ -40,7 +40,7 @@ export interface CheckService extends OnlyId {
forceSave: boolean,
dualCerts: boolean,
exposePort: number,
otherFqdns: Array<string>
otherFqdn: boolean
}
}
export interface SaveService extends OnlyId {

View File

@ -16,6 +16,7 @@
}
</script>
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
<div class="dropdown dropdown-bottom">
<slot>
<label for="new" tabindex="0" class="btn btn-sm text-sm bg-coollabs hover:bg-coollabs-100 w-64">

View File

@ -541,6 +541,7 @@
</div>
<div class="form-control">
<div class="input-group flex w-full">
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div
class="btn btn-square cursor-default no-animation hover:bg-error"
on:click={() => doSearch('')}

View File

@ -78,13 +78,29 @@
if (loading.save) return;
loading.save = true;
try {
const formData = new FormData(e.target);
await post(`/services/${id}/check`, {
fqdn: service.fqdn,
forceSave,
dualCerts,
exposePort: service.exposePort
});
const formData = new FormData(e.target);
for (const setting of service.serviceSetting) {
if (setting.variableName.startsWith('$$coolify_fqdn') && setting.value) {
for (let field of formData) {
const [key, value] = field;
if (setting.name === key) {
if (setting.value !== value) {
await post(`/services/${id}/check`, {
fqdn: value,
otherFqdn: true
});
}
}
}
}
}
if (formData) service = await saveForm(formData, service);
setLocation(service);
forceSave = false;