mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
add subdomain based redirection; redirect chat.lbry.io
This commit is contained in:
parent
bccdf1277e
commit
abe242e86e
2 changed files with 36 additions and 0 deletions
|
@ -58,6 +58,7 @@ class Controller
|
||||||
public static function execute($method, $uri)
|
public static function execute($method, $uri)
|
||||||
{
|
{
|
||||||
$router = static::getRouterWithRoutes();
|
$router = static::getRouterWithRoutes();
|
||||||
|
static::performSubdomainRedirects();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$dispatcher = new Routing\Dispatcher($router->getData());
|
$dispatcher = new Routing\Dispatcher($router->getData());
|
||||||
|
@ -75,6 +76,17 @@ class Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static function performSubdomainRedirects()
|
||||||
|
{
|
||||||
|
$subDomain = Request::getSubDomain();
|
||||||
|
|
||||||
|
switch($subDomain) {
|
||||||
|
case 'chat':
|
||||||
|
case 'slack':
|
||||||
|
return static::redirect('https://discordapp.com/invite/U5aRyN6');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected static function getRouterWithRoutes(): \Routing\RouteCollector
|
protected static function getRouterWithRoutes(): \Routing\RouteCollector
|
||||||
{
|
{
|
||||||
$router = new Routing\RouteCollector();
|
$router = new Routing\RouteCollector();
|
||||||
|
|
|
@ -92,6 +92,30 @@ class Request
|
||||||
return static::getHttpHeader('Host') ? rtrim(static::getHttpHeader('Host'), '.') : '';
|
return static::getHttpHeader('Host') ? rtrim(static::getHttpHeader('Host'), '.') : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getSubDomain(): string
|
||||||
|
{
|
||||||
|
$urlParts = parse_url(static::getHost());
|
||||||
|
$host = $urlParts['host'] ?? '';
|
||||||
|
$domainParts = explode('.', $host);
|
||||||
|
$domainPartCount = count($domainParts);
|
||||||
|
|
||||||
|
if (count($domainParts) < 1)
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$isLocalhost = $domainParts[$domainPartCount - 1] === 'localhost';
|
||||||
|
|
||||||
|
if (!$isLocalhost && count($domainParts) < 2)
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $isLocalhost ?
|
||||||
|
$domainParts[$domainPartCount - 2] :
|
||||||
|
$domainParts[$domainPartCount - 3];
|
||||||
|
}
|
||||||
|
|
||||||
public static function getHostAndProto(): string
|
public static function getHostAndProto(): string
|
||||||
{
|
{
|
||||||
return (static::isSSL() ? 'https' : 'http') . '://' . static::getHost();
|
return (static::isSSL() ? 'https' : 'http') . '://' . static::getHost();
|
||||||
|
|
Loading…
Add table
Reference in a new issue