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)
{
$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

View file

@ -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);

View file

@ -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'];
}