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) <noreply@anthropic.com>
This commit is contained in:
Jonathan Miller
2026-05-31 13:10:01 -05:00
parent 6d28d83f86
commit ede0711dc6
2 changed files with 77 additions and 122 deletions
@@ -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
+1 -25
View File
@@ -177,31 +177,7 @@
label="PLG_SYSTEM_MOKOWAAS_DEMO_TASK_INFO_LABEL"
/>
</fieldset>
<fieldset name="site_aliases"
label="PLG_SYSTEM_MOKOWAAS_FIELDSET_ALIASES_LABEL"
description="PLG_SYSTEM_MOKOWAAS_FIELDSET_ALIASES_DESC"
>
<field
name="primary_domain"
type="text"
label="PLG_SYSTEM_MOKOWAAS_PRIMARY_DOMAIN_LABEL"
description="PLG_SYSTEM_MOKOWAAS_PRIMARY_DOMAIN_DESC"
default=""
hint="e.g. waas.dev.mokoconsulting.tech"
/>
<field
name="site_aliases"
type="subform"
label="PLG_SYSTEM_MOKOWAAS_SITE_ALIASES_LABEL"
description="PLG_SYSTEM_MOKOWAAS_SITE_ALIASES_DESC"
formsource="plugins/system/mokowaas/forms/alias_entry.xml"
multiple="true"
layout="joomla.form.field.subform.repeatable-table"
groupByFieldset="false"
buttons="add,remove,move"
/>
</fieldset>
<fieldset name="security"
<fieldset name="security"
label="PLG_SYSTEM_MOKOWAAS_FIELDSET_SECURITY_LABEL"
description="PLG_SYSTEM_MOKOWAAS_FIELDSET_SECURITY_DESC"
addfieldprefix="Moko\Plugin\System\MokoWaaS\Field"