From ede0711dc66b3bebde892dabe2173e44d8dbd544 Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Sun, 31 May 2026 13:10:01 -0500 Subject: [PATCH] feat: hardcode dev alias, remove site_aliases config, auto-set primary domain - Site alias is now hardcoded to dev.{primary_domain} - dev.* subdomain bypasses offline mode for development access - dev.* subdomain gets noindex/nofollow robots meta - Primary domain auto-detected on first config save - Removed site_aliases config tab and subform Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) --- .../Extension/MokoWaaS.php | 173 ++++++++---------- src/packages/plg_system_mokowaas/mokowaas.xml | 26 +-- 2 files changed, 77 insertions(+), 122 deletions(-) diff --git a/src/packages/plg_system_mokowaas/Extension/MokoWaaS.php b/src/packages/plg_system_mokowaas/Extension/MokoWaaS.php index 135dbcc..46288fa 100644 --- a/src/packages/plg_system_mokowaas/Extension/MokoWaaS.php +++ b/src/packages/plg_system_mokowaas/Extension/MokoWaaS.php @@ -863,6 +863,23 @@ class MokoWaaS extends CMSPlugin implements BootableExtensionInterface ); } + // Auto-set primary domain on first save + if (empty($params->get('primary_domain', ''))) + { + $host = parse_url(Uri::root(), PHP_URL_HOST) ?: ($_SERVER['HTTP_HOST'] ?? ''); + + if (!empty($host)) + { + $params->set('primary_domain', $host); + $changed = true; + + $app->enqueueMessage( + 'Primary domain set to: ' . $host, + 'message' + ); + } + } + // Grafana auto-provisioning $this->handleGrafanaProvisioning($params, $app); @@ -3739,7 +3756,6 @@ class MokoWaaS extends CMSPlugin implements BootableExtensionInterface */ protected function getPrimaryHost(): string { - // Try plugin's primary_domain setting first $primaryDomain = $this->params->get('primary_domain', ''); if (!empty($primaryDomain)) @@ -3747,7 +3763,7 @@ class MokoWaaS extends CMSPlugin implements BootableExtensionInterface return trim($primaryDomain); } - // Try Joomla's $live_site + // Fallback: Joomla's $live_site $liveSite = Factory::getConfig()->get('live_site', ''); if (!empty($liveSite)) @@ -3760,47 +3776,36 @@ class MokoWaaS extends CMSPlugin implements BootableExtensionInterface } } - // Fallback: if current host is NOT in the aliases list, it's the primary + return parse_url(Uri::root(), PHP_URL_HOST) ?: ($_SERVER['HTTP_HOST'] ?? ''); + } + + /** + * Get the dev alias domain (dev.{primary_domain}). + * + * @return string + * + * @since 02.31.00 + */ + protected function getDevAliasDomain(): string + { + $primary = $this->getPrimaryHost(); + + return !empty($primary) ? 'dev.' . $primary : ''; + } + + /** + * Check if the current request is on the dev alias domain. + * + * @return bool + * + * @since 02.31.00 + */ + protected function isDevAlias(): bool + { $currentHost = $_SERVER['HTTP_HOST'] ?? ''; - $aliases = $this->params->get('site_aliases', ''); + $devDomain = $this->getDevAliasDomain(); - if (!empty($aliases)) - { - if (is_string($aliases)) - { - $aliases = json_decode($aliases); - } - - if (is_object($aliases)) - { - $aliases = (array) $aliases; - } - - if (is_array($aliases)) - { - $isAlias = false; - - foreach ($aliases as $a) - { - $a = (object) $a; - - if (isset($a->domain) && strcasecmp(rtrim(trim($a->domain), '/'), $currentHost) === 0) - { - $isAlias = true; - break; - } - } - - // If current host is NOT an alias, it's the primary - if (!$isAlias) - { - return $currentHost; - } - } - } - - // Last resort: use Uri::root() (may be wrong on alias domains) - return parse_url(Uri::root(), PHP_URL_HOST) ?: $currentHost; + return !empty($devDomain) && strcasecmp($currentHost, $devDomain) === 0; } protected function getCurrentAlias() @@ -3812,6 +3817,29 @@ class MokoWaaS extends CMSPlugin implements BootableExtensionInterface return null; } + // The only alias is dev.{primary_domain} + $devDomain = $this->getDevAliasDomain(); + + if (empty($devDomain) || strcasecmp($currentHost, $devDomain) !== 0) + { + return null; + } + + // Return a synthetic alias object for the dev domain + return (object) [ + 'domain' => $devDomain, + 'offline' => '0', + 'redirect_backend' => '0', + 'robots' => 'noindex, nofollow', + ]; + } + + /** + * Legacy compatibility — old getCurrentAlias read from site_aliases param. + * Now only returns the hardcoded dev.* alias. + */ + private function getCurrentAliasLegacy() + { $aliases = $this->params->get('site_aliases', ''); if (empty($aliases)) @@ -3862,54 +3890,13 @@ class MokoWaaS extends CMSPlugin implements BootableExtensionInterface */ protected function handleSiteAlias() { - $alias = $this->getCurrentAlias(); - - if ($alias === null) + // The dev alias (dev.{primary_domain}) always bypasses offline mode + if ($this->isDevAlias()) { + $this->app->getConfig()->set('offline', 0); + return; } - - // Backend redirect: send admin requests to the primary domain - if (!empty($alias->redirect_backend) && $alias->redirect_backend === '1' - && $this->app->isClient('administrator')) - { - $primaryHost = $this->getPrimaryHost(); - $currentUri = Uri::getInstance(); - $scheme = $currentUri->getScheme() ?: 'https'; - $primaryUrl = $scheme . '://' . $primaryHost . $currentUri->toString(['path', 'query']); - - $this->app->redirect($primaryUrl, 301); - } - - // Offline: use Joomla's native offline mode for frontend requests - if ($this->app->isClient('site')) - { - if (!empty($alias->offline) && (string) $alias->offline === '1') - { - // Allow health API to still respond - if ($this->app->input->get('mokowaas', '') !== '') - { - return; - } - - // Set custom offline message if provided - $message = $alias->offline_message ?? ''; - - if (!empty($message)) - { - $this->app->getConfig()->set('offline_message', $message); - } - - // Enable Joomla's native offline mode - $this->app->getConfig()->set('offline', 1); - } - else - { - // Alias is NOT offline — override Joomla's global offline setting - // This allows access via the alias domain even when the main site is offline - $this->app->getConfig()->set('offline', 0); - } - } } /** @@ -3923,18 +3910,10 @@ class MokoWaaS extends CMSPlugin implements BootableExtensionInterface */ protected function injectAliasRobots($doc) { - $alias = $this->getCurrentAlias(); - - if ($alias === null) + // Always noindex/nofollow on the dev alias domain + if ($this->isDevAlias()) { - return; - } - - $robots = $alias->robots ?? 'index, follow'; - - if ($robots !== 'index, follow') - { - $doc->setMetaData('robots', $robots); + $doc->setMetaData('robots', 'noindex, nofollow'); } // Inject canonical URL pointing to the primary domain diff --git a/src/packages/plg_system_mokowaas/mokowaas.xml b/src/packages/plg_system_mokowaas/mokowaas.xml index d2e5df3..920104c 100644 --- a/src/packages/plg_system_mokowaas/mokowaas.xml +++ b/src/packages/plg_system_mokowaas/mokowaas.xml @@ -177,31 +177,7 @@ label="PLG_SYSTEM_MOKOWAAS_DEMO_TASK_INFO_LABEL" /> -
- - -
-