From cb359e40bac65e678fce60ba55715843fba6cd14 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 18 Nov 2024 00:23:45 +0530 Subject: [PATCH 1/2] Add fallbackFile for SPA --- app/config/collections.php | 11 +++++++++++ .../Platform/Modules/Sites/Http/Sites/CreateSite.php | 4 +++- .../Platform/Modules/Sites/Http/Sites/UpdateSite.php | 6 ++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index c8866f8116..e5a3d8ac7b 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -3336,6 +3336,17 @@ $projectCollections = array_merge([ 'default' => null, 'filters' => [], ], + [ + '$id' => ID::custom('fallbackFile'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('deploymentInternalId'), 'type' => Database::VAR_STRING, diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/CreateSite.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/CreateSite.php index b98dc1bb07..762dbfbe35 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/CreateSite.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/CreateSite.php @@ -69,6 +69,7 @@ class CreateSite extends Base ->param('buildRuntime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Runtime to use during build step.') ->param('serveRuntime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Runtime to use when serving site.') ->param('installationId', '', new Text(128, 0), 'Appwrite Installation ID for VCS (Version Control System) deployment.', true) + ->param('fallbackFile', '', new Text(255, 0), 'Fallback file for single page application sites.', true) ->param('providerRepositoryId', '', new Text(128, 0), 'Repository ID of the repo linked to the site.', true) ->param('providerBranch', '', new Text(128, 0), 'Production branch for the repo linked to the site.', true) ->param('providerSilentMode', false, new Boolean(), 'Is the VCS (Version Control System) connection in silent mode for the repo linked to the site? In silent mode, comments will not be made on commits and pull requests.', true) @@ -95,7 +96,7 @@ class CreateSite extends Base ->callback([$this, 'action']); } - public function action(string $siteId, string $name, string $framework, bool $enabled, int $timeout, string $installCommand, string $buildCommand, string $outputDirectory, string $subdomain, string $buildRuntime, string $serveRuntime, string $installationId, string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, string $templateRepository, string $templateOwner, string $templateRootDirectory, string $templateVersion, string $specification, Request $request, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github) + public function action(string $siteId, string $name, string $framework, bool $enabled, int $timeout, string $installCommand, string $buildCommand, string $outputDirectory, string $subdomain, string $buildRuntime, string $serveRuntime, string $installationId, string $fallbackFile, string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, string $templateRepository, string $templateOwner, string $templateRootDirectory, string $templateVersion, string $specification, Request $request, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github) { $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', ''); $ruleId = ''; @@ -161,6 +162,7 @@ class CreateSite extends Base 'buildCommand' => $buildCommand, 'outputDirectory' => $outputDirectory, 'search' => implode(' ', [$siteId, $name, $framework]), + 'fallbackFile' => $fallbackFile, 'installationId' => $installation->getId(), 'installationInternalId' => $installation->getInternalId(), 'providerRepositoryId' => $providerRepositoryId, diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/UpdateSite.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/UpdateSite.php index 5f03b337f7..4a8d73c9bf 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/UpdateSite.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/UpdateSite.php @@ -64,6 +64,7 @@ class UpdateSite extends Base ->param('outputDirectory', '', new Text(8192, 0), 'Output Directory for site.', true) ->param('buildRuntime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Runtime to use during build step.', true) ->param('serveRuntime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Runtime to use when serving site.', true) + ->param('fallbackFile', '', new Text(255, 0), 'Fallback file for single page application sites.', true) ->param('installationId', '', new Text(128, 0), 'Appwrite Installation ID for VCS (Version Control System) deployment.', true) ->param('providerRepositoryId', '', new Text(128, 0), 'Repository ID of the repo linked to the site.', true) ->param('providerBranch', '', new Text(128, 0), 'Production branch for the repo linked to the site.', true) @@ -86,7 +87,7 @@ class UpdateSite extends Base ->callback([$this, 'action']); } - public function action(string $siteId, string $name, string $framework, bool $enabled, int $timeout, string $installCommand, string $buildCommand, string $outputDirectory, string $buildRuntime, string $serveRuntime, string $installationId, ?string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, string $specification, Request $request, Response $response, Database $dbForProject, Document $project, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github) + public function action(string $siteId, string $name, string $framework, bool $enabled, int $timeout, string $installCommand, string $buildCommand, string $outputDirectory, string $buildRuntime, string $serveRuntime, string $fallbackFile, string $installationId, ?string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, string $specification, Request $request, Response $response, Database $dbForProject, Document $project, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github) { // TODO: If only branch changes, re-deploy $site = $dbForProject->getDocument('sites', $siteId); @@ -218,7 +219,8 @@ class UpdateSite extends Base 'specification' => $specification, 'search' => implode(' ', [$siteId, $name, $framework]), 'buildRuntime' => $buildRuntime, - 'serveRuntime' => $serveRuntime + 'serveRuntime' => $serveRuntime, + 'fallbackFile' => $fallbackFile, ]))); // Redeploy logic From 4bcbd49d6d7a358d660de6114211b6afb80804a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 20 Nov 2024 14:18:43 +0100 Subject: [PATCH 2/2] Formatting fix --- app/controllers/api/vcs.php | 2 +- app/controllers/general.php | 6 +++--- src/Appwrite/Platform/Modules/Compute/Base.php | 2 +- .../Platform/Modules/Sites/Http/Sites/CreateSite.php | 3 +-- .../Platform/Modules/Sites/Http/Sites/UpdateSite.php | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index 4cba746029..c644f18a1d 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -235,7 +235,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId $ruleId = md5($domain); $rule = Authorization::skip( - fn() => $dbForConsole->createDocument('rules', new Document([ + fn () => $dbForConsole->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), 'projectInternalId' => $project->getInternalId(), diff --git a/app/controllers/general.php b/app/controllers/general.php index 5cf4f83484..0d42357b95 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -1030,7 +1030,7 @@ App::get('/robots.txt') $template = new View(__DIR__ . '/../views/general/robots.phtml'); $response->text($template->render(false)); } else { - if(router($utopia, $dbForConsole, $getProjectDB, $swooleRequest, $request, $response, $queueForEvents, $queueForUsage, $queueForFunctions, $geodb, $isResourceBlocked)) { + if (router($utopia, $dbForConsole, $getProjectDB, $swooleRequest, $request, $response, $queueForEvents, $queueForUsage, $queueForFunctions, $geodb, $isResourceBlocked)) { $utopia->getRoute()?->label('router', 'true'); } } @@ -1059,7 +1059,7 @@ App::get('/humans.txt') $template = new View(__DIR__ . '/../views/general/humans.phtml'); $response->text($template->render(false)); } else { - if(router($utopia, $dbForConsole, $getProjectDB, $swooleRequest, $request, $response, $queueForEvents, $queueForUsage, $queueForFunctions, $geodb, $isResourceBlocked)) { + if (router($utopia, $dbForConsole, $getProjectDB, $swooleRequest, $request, $response, $queueForEvents, $queueForUsage, $queueForFunctions, $geodb, $isResourceBlocked)) { $utopia->getRoute()?->label('router', 'true'); } } @@ -1156,7 +1156,7 @@ App::wildcard() ->inject('utopia') ->action(function (App $utopia) { $handeledByRouter = $utopia->getRoute()?->getLabel('router', 'false'); - if(\boolval($handeledByRouter)) { + if (\boolval($handeledByRouter)) { return; } diff --git a/src/Appwrite/Platform/Modules/Compute/Base.php b/src/Appwrite/Platform/Modules/Compute/Base.php index 4fb872fe2e..c6e5653724 100644 --- a/src/Appwrite/Platform/Modules/Compute/Base.php +++ b/src/Appwrite/Platform/Modules/Compute/Base.php @@ -169,7 +169,7 @@ class Base extends Action $ruleId = md5($domain); $rule = Authorization::skip( - fn() => $dbForConsole->createDocument('rules', new Document([ + fn () => $dbForConsole->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), 'projectInternalId' => $project->getInternalId(), diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/CreateSite.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/CreateSite.php index 369d1bd82c..5c8081ece7 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/CreateSite.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/CreateSite.php @@ -18,7 +18,6 @@ use Utopia\Database\Document; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Role; -use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; @@ -233,7 +232,7 @@ class CreateSite extends Base $previewDomain = "{$deploymentId}-{$projectId}.{$sitesDomain}"; $rule = Authorization::skip( - fn() => $dbForConsole->createDocument('rules', new Document([ + fn () => $dbForConsole->createDocument('rules', new Document([ '$id' => \md5($previewDomain), 'projectId' => $project->getId(), 'projectInternalId' => $project->getInternalId(), diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/UpdateSite.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/UpdateSite.php index 4a8d73c9bf..1e310dc523 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/UpdateSite.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/UpdateSite.php @@ -87,7 +87,7 @@ class UpdateSite extends Base ->callback([$this, 'action']); } - public function action(string $siteId, string $name, string $framework, bool $enabled, int $timeout, string $installCommand, string $buildCommand, string $outputDirectory, string $buildRuntime, string $serveRuntime, string $fallbackFile, string $installationId, ?string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, string $specification, Request $request, Response $response, Database $dbForProject, Document $project, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github) + public function action(string $siteId, string $name, string $framework, bool $enabled, int $timeout, string $installCommand, string $buildCommand, string $outputDirectory, string $buildRuntime, string $serveRuntime, string $fallbackFile, string $installationId, ?string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, string $specification, Request $request, Response $response, Database $dbForProject, Document $project, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github) { // TODO: If only branch changes, re-deploy $site = $dbForProject->getDocument('sites', $siteId);