fix domain routing

This commit is contained in:
Jeremy Kauffman 2019-02-05 16:56:59 -05:00
parent 0b1f00b2f8
commit 18aa28a59b
3 changed files with 24 additions and 19 deletions

View file

@ -49,7 +49,12 @@ class Controller
public static function execute($method, $uri) public static function execute($method, $uri)
{ {
$router = static::getRouterWithRoutes(); $router = static::getRouterWithRoutes();
static::performSubdomainRedirects();
$domainResult = static::performDomainRouting($uri);
if ($domainResult) {
return $domainResult;
}
try { try {
$dispatcher = new Routing\Dispatcher($router->getData()); $dispatcher = new Routing\Dispatcher($router->getData());
return $dispatcher->dispatch($method, $uri); return $dispatcher->dispatch($method, $uri);
@ -62,7 +67,7 @@ class Controller
} }
} }
protected static function performSubdomainRedirects() protected static function performDomainRouting($uri)
{ {
$subDomain = Request::getSubDomain(); $subDomain = Request::getSubDomain();
@ -71,6 +76,19 @@ class Controller
case 'slack': case 'slack':
return static::redirect('https://discord.gg/Z3bERWA'); 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 protected static function getRouterWithRoutes(): \Routing\RouteCollector

View file

@ -121,11 +121,6 @@ class Request
return static::getHeader('HTTPS') || strtolower(static::getHttpHeader('X_FORWARDED_PROTO')) == 'https'; 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 = '/') public static function getReferrer(string $fallback = '/')
{ {
return Request::getHttpHeader('Referer', $fallback); return Request::getHttpHeader('Referer', $fallback);

View file

@ -29,14 +29,6 @@ class ContentActions extends Actions
public static function executeHome(): array public static function executeHome(): array
{ {
Response::enableHttpCache(); Response::enableHttpCache();
$serverName = Request::getServerName();
if ($serverName === 'lbry.org') {
return static::executeOrg();
} else if ($serverName === 'lbry.tv') {
return static::executeTv();
}
return ['page/home']; return ['page/home'];
} }