diff --git a/controller/Controller.class.php b/controller/Controller.class.php index 28875fc7..e892d54a 100644 --- a/controller/Controller.class.php +++ b/controller/Controller.class.php @@ -49,7 +49,12 @@ class Controller public static function execute($method, $uri) { $router = static::getRouterWithRoutes(); - static::performSubdomainRedirects(); + + $domainResult = static::performDomainRouting($uri); + if ($domainResult) { + return $domainResult; + } + try { $dispatcher = new Routing\Dispatcher($router->getData()); return $dispatcher->dispatch($method, $uri); @@ -62,15 +67,28 @@ class Controller } } - protected static function performSubdomainRedirects() + protected static function performDomainRouting($uri) { $subDomain = Request::getSubDomain(); switch ($subDomain) { - case 'chat': - case 'slack': - return static::redirect('https://discord.gg/Z3bERWA'); - } + case 'chat': + case 'slack': + return static::redirect('https://discord.gg/Z3bERWA'); + } + + $hostName = $_SERVER['HTTP_HOST']; + if ($hostName && in_array($hostName, ['lbry.org', 'lbry.tv'])) { + if ($uri !== '/') { + return static::redirect('/'); + } + switch($hostName) { + case 'lbry.org': + return ContentActions::executeOrg(); + case 'lbry.tv': + return ContentActions::executeTv(); + } + } } protected static function getRouterWithRoutes(): \Routing\RouteCollector diff --git a/controller/Request.class.php b/controller/Request.class.php index 09dd5351..9efacd2a 100644 --- a/controller/Request.class.php +++ b/controller/Request.class.php @@ -121,11 +121,6 @@ class Request return static::getHeader('HTTPS') || strtolower(static::getHttpHeader('X_FORWARDED_PROTO')) == 'https'; } - public static function getServerName(): string - { - return static::getHeader('SERVER_NAME'); - } - public static function getReferrer(string $fallback = '/') { return Request::getHttpHeader('Referer', $fallback); diff --git a/controller/action/ContentActions.class.php b/controller/action/ContentActions.class.php index 9797dbe8..8d1ee61e 100644 --- a/controller/action/ContentActions.class.php +++ b/controller/action/ContentActions.class.php @@ -29,14 +29,6 @@ class ContentActions extends Actions public static function executeHome(): array { Response::enableHttpCache(); - - $serverName = Request::getServerName(); - if ($serverName === 'lbry.org') { - return static::executeOrg(); - } else if ($serverName === 'lbry.tv') { - return static::executeTv(); - } - return ['page/home']; }