diff --git a/app/console b/app/console index a4d777092e..08060d1a19 160000 --- a/app/console +++ b/app/console @@ -1 +1 @@ -Subproject commit a4d777092e7a8fa0d0856d4d41c502b85b398e7f +Subproject commit 08060d1a19d1d74f52ac35ce7635cca28607ab1f diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index 2b1cf3dad4..76312b9cee 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -82,14 +82,7 @@ App::post('/v1/proxy/rules') $domain = new Domain($domain); $ruleId = ID::unique(); - - $status = 'created'; - $functionsDomain = App::getEnv('_APP_DOMAIN_FUNCTIONS', 'disabled'); - if ($functionsDomain !== 'disabled' && \str_ends_with($domain->get(), $functionsDomain)) { - $status = 'verified'; - } - - $rule = $dbForConsole->createDocument('rules', new Document([ + $rule = new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), 'projectInternalId' => $project->getInternalId(), @@ -97,9 +90,33 @@ App::post('/v1/proxy/rules') 'resourceType' => $resourceType, 'resourceId' => $resourceId, 'resourceInternalId' => $resourceInternalId, - 'status' => $status, 'certificateId' => '', - ])); + ]); + + $status = 'created'; + $functionsDomain = App::getEnv('_APP_DOMAIN_FUNCTIONS', 'disabled'); + if ($functionsDomain !== 'disabled' && \str_ends_with($domain->get(), $functionsDomain)) { + $status = 'verified'; + } + + if ($status === 'created') { + $target = new Domain(App::getEnv('_APP_DOMAIN_TARGET', '')); + $validator = new CNAME($target->get()); // Verify Domain with DNS records + + if ($validator->isValid($domain->get())) { + $status = 'verifying'; + + $event = new Certificate(); + $event + ->setDomain(new Document([ + 'domain' => $rule->getAttribute('domain') + ])) + ->trigger(); + } + } + + $rule->setAttribute('status', $status); + $rule = $dbForConsole->createDocument('rules', $rule); $events->setParam('ruleId', $rule->getId());