mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
fix(console): redirect legacy web paths to console routes
/login, /register, /recover and /invite land on /sign-in, /sign-up, /reset and /join on the console URL, while /, /auth/* and /mfa keep their path. The /card redirect is removed since the console has no card page. Requests already on the console host are not redirected, so they cannot loop back through the proxy.
This commit is contained in:
1 parent
514c9e4d25
commit
9fd34b73a7
8 files changed
+52
-39
No files matched your search
@@ -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);
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Console\Http\Redirects\Card;
|
||||
|
||||
use Appwrite\Platform\Modules\Console\Http\Redirects\Base;
|
||||
|
||||
class Get extends Base
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'consoleRedirectCard';
|
||||
}
|
||||
|
||||
protected function getPath(): string
|
||||
{
|
||||
return '/card/*';
|
||||
}
|
||||
}
|
||||
@@ -15,4 +15,9 @@ class Get extends Base
|
||||
{
|
||||
return '/invite';
|
||||
}
|
||||
|
||||
protected function getTarget(string $path): string
|
||||
{
|
||||
return '/join';
|
||||
}
|
||||
}
|
||||
@@ -15,4 +15,9 @@ class Get extends Base
|
||||
{
|
||||
return '/login';
|
||||
}
|
||||
|
||||
protected function getTarget(string $path): string
|
||||
{
|
||||
return '/sign-in';
|
||||
}
|
||||
}
|
||||
@@ -15,4 +15,9 @@ class Get extends Base
|
||||
{
|
||||
return '/recover';
|
||||
}
|
||||
|
||||
protected function getTarget(string $path): string
|
||||
{
|
||||
return '/reset';
|
||||
}
|
||||
}
|
||||
@@ -15,4 +15,9 @@ class Get extends Base
|
||||
{
|
||||
return '/register/*';
|
||||
}
|
||||
|
||||
protected function getTarget(string $path): string
|
||||
{
|
||||
return '/sign-up';
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ use Appwrite\Platform\Modules\Console\Http\Init\API;
|
||||
use Appwrite\Platform\Modules\Console\Http\Init\Web;
|
||||
use Appwrite\Platform\Modules\Console\Http\OAuth2Providers\XList as ListOAuth2Providers;
|
||||
use Appwrite\Platform\Modules\Console\Http\Redirects\Auth\Get as RedirectAuth;
|
||||
use Appwrite\Platform\Modules\Console\Http\Redirects\Card\Get as RedirectCard;
|
||||
use Appwrite\Platform\Modules\Console\Http\Redirects\Invite\Get as RedirectInvite;
|
||||
use Appwrite\Platform\Modules\Console\Http\Redirects\Login\Get as RedirectLogin;
|
||||
use Appwrite\Platform\Modules\Console\Http\Redirects\MFA\Get as RedirectMFA;
|
||||
@@ -20,7 +19,6 @@ use Appwrite\Platform\Modules\Console\Http\Scopes\Project\XList as ListKeyScopes
|
||||
use Appwrite\Platform\Modules\Console\Http\Templates\Email\Get as GetEmailTemplate;
|
||||
use Appwrite\Platform\Modules\Console\Http\Variables\Get as GetVariables;
|
||||
use Utopia\Platform\Service;
|
||||
use Utopia\System\System;
|
||||
|
||||
class Http extends Service
|
||||
{
|
||||
@@ -40,16 +38,13 @@ class Http extends Service
|
||||
$this->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());
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user