diff --git a/src/Appwrite/Platform/Modules/Console/Http/Redirects/Base.php b/src/Appwrite/Platform/Modules/Console/Http/Redirects/Base.php index 4b36319255..7c426731d4 100644 --- a/src/Appwrite/Platform/Modules/Console/Http/Redirects/Base.php +++ b/src/Appwrite/Platform/Modules/Console/Http/Redirects/Base.php @@ -2,6 +2,7 @@ namespace Appwrite\Platform\Modules\Console\Http\Redirects; +use Appwrite\Extend\Exception; use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; use Utopia\Platform\Action; @@ -21,6 +22,14 @@ abstract class Base extends Action */ abstract protected function getPath(): string; + /** + * Console route to land on, the request path unless the console names it differently. + */ + protected function getTarget(string $path): string + { + return $path; + } + public function __construct() { $this @@ -31,13 +40,21 @@ abstract class Base extends Action ->label('scope', 'home') ->inject('request') ->inject('response') + ->inject('platform') ->callback($this->action(...)); } - public function action(Request $request, Response $response): void + public function action(Request $request, Response $response, array $platform): void { + $consoleUrl = $platform['consoleUrl'] ?? ''; + + // On the console's own host the proxy serves these paths, so redirecting would loop + if ($request->getHostname() === \parse_url($consoleUrl, PHP_URL_HOST)) { + throw new Exception(Exception::GENERAL_ROUTE_NOT_FOUND); + } + $url = parse_url($request->getURI()); - $target = "/console" . ($url['path'] ?? ''); + $target = $consoleUrl . $this->getTarget($url['path'] ?? ''); $params = $request->getParams(); if (!empty($params)) { $target .= "?" . \http_build_query($params); diff --git a/src/Appwrite/Platform/Modules/Console/Http/Redirects/Card/Get.php b/src/Appwrite/Platform/Modules/Console/Http/Redirects/Card/Get.php deleted file mode 100644 index c98c125f4e..0000000000 --- a/src/Appwrite/Platform/Modules/Console/Http/Redirects/Card/Get.php +++ /dev/null @@ -1,18 +0,0 @@ -addAction(CreateAssistantQuery::getName(), new CreateAssistantQuery()); $this->addAction(GetResourceAvailability::getName(), new GetResourceAvailability()); - // web redirects to /console, only where the console is served under /console - if (System::getEnv('_APP_CONSOLE_URL_SCHEME', 'legacy') !== 'root') { - $this->addAction(RedirectRoot::getName(), new RedirectRoot()); - $this->addAction(RedirectAuth::getName(), new RedirectAuth()); - $this->addAction(RedirectInvite::getName(), new RedirectInvite()); - $this->addAction(RedirectLogin::getName(), new RedirectLogin()); - $this->addAction(RedirectMFA::getName(), new RedirectMFA()); - $this->addAction(RedirectCard::getName(), new RedirectCard()); - $this->addAction(RedirectRecover::getName(), new RedirectRecover()); - $this->addAction(RedirectRegister::getName(), new RedirectRegister()); - } + // web redirects to the console + $this->addAction(RedirectRoot::getName(), new RedirectRoot()); + $this->addAction(RedirectAuth::getName(), new RedirectAuth()); + $this->addAction(RedirectInvite::getName(), new RedirectInvite()); + $this->addAction(RedirectLogin::getName(), new RedirectLogin()); + $this->addAction(RedirectMFA::getName(), new RedirectMFA()); + $this->addAction(RedirectRecover::getName(), new RedirectRecover()); + $this->addAction(RedirectRegister::getName(), new RedirectRegister()); } } diff --git a/tests/e2e/General/HTTPTest.php b/tests/e2e/General/HTTPTest.php index ecbd88f822..d9e9d2c9e5 100644 --- a/tests/e2e/General/HTTPTest.php +++ b/tests/e2e/General/HTTPTest.php @@ -9,7 +9,6 @@ use Tests\E2E\Scopes\ProjectNone; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideNone; use Utopia\Config\Config; -use Utopia\System\System; final class HTTPTest extends Scope { @@ -121,11 +120,11 @@ final class HTTPTest extends Scope public function testDefaultOAuth2() { - $response = $this->client->call(Client::METHOD_GET, '/console/auth/oauth2/success', $this->getHeaders()); + $response = $this->client->call(Client::METHOD_GET, '/auth/oauth2/success', $this->getHeaders()); $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_GET, '/console/auth/oauth2/failure', $this->getHeaders()); + $response = $this->client->call(Client::METHOD_GET, '/auth/oauth2/failure', $this->getHeaders()); $this->assertEquals(200, $response['headers']['status-code']); } @@ -240,10 +239,10 @@ final class HTTPTest extends Scope $endpoint = '/invite?membershipId=123&userId=asdf'; - $response = $this->client->call(Client::METHOD_GET, $endpoint, [], [], true, false); + // Requests on the console's own host are left to the proxy, so arrive on the API host + $response = $this->client->call(Client::METHOD_GET, $endpoint, ['host' => 'appwrite.test'], [], true, false); - $location = System::getEnv('_APP_CONSOLE_URL_SCHEME', 'legacy') !== 'root' ? '/console' . $endpoint : null; - $this->assertEquals($location, $response['headers']['location'] ?? null); + $this->assertEquals('http://localhost/join?membershipId=123&userId=asdf', $response['headers']['location']); } public function testConsoleServed()