diff --git a/app/controllers/general.php b/app/controllers/general.php index f2362544c6..d4728fb5af 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -555,7 +555,7 @@ App::init() */ App::init() - ->groups(['database', 'functions', 'messaging']) + ->groups(['database', 'functions', 'sites', 'messaging']) ->inject('project') ->inject('request') ->action(function (Document $project, Request $request) { diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Templates/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Templates/Get.php index 6819f6693c..e624b26de6 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Templates/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Templates/Get.php @@ -30,7 +30,6 @@ class Get extends Base ->setHttpPath('/v1/functions/templates/:templateId') ->desc('Get function template') ->label('scope', 'public') - ->groups(['api', 'functions']) ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php index 3250874ac5..619ad6a315 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php @@ -29,9 +29,8 @@ class XList extends Base $this ->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/functions/templates') - ->desc('List function templates') + ->desc('List templates') ->label('scope', 'public') - ->groups(['api', 'functions']) ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Templates/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Templates/Get.php index b994dd2172..9d2991bce9 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Templates/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Templates/Get.php @@ -30,7 +30,6 @@ class Get extends Base ->setHttpPath('/v1/sites/templates/:templateId') ->desc('Get site template') ->label('scope', 'public') - ->groups(['api', 'sites']) ->label('sdk', new Method( namespace: 'sites', name: 'getTemplate', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php index 00ece7f68b..3c27b75578 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php @@ -31,7 +31,6 @@ class XList extends Base ->setHttpPath('/v1/sites/templates') ->desc('List templates') ->label('scope', 'public') - ->groups(['api', 'sites']) ->label('sdk', new Method( namespace: 'sites', name: 'listTemplates', diff --git a/tests/e2e/Scopes/ProjectCustom.php b/tests/e2e/Scopes/ProjectCustom.php index f2617bd4be..f8f779027b 100644 --- a/tests/e2e/Scopes/ProjectCustom.php +++ b/tests/e2e/Scopes/ProjectCustom.php @@ -82,6 +82,8 @@ trait ProjectCustom 'sites.write', 'execution.read', 'execution.write', + 'log.read', + 'log.write', 'locale.read', 'avatars.read', 'health.read', diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 914a255663..9d8ce5a4ee 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -276,7 +276,7 @@ class FunctionsCustomClientTest extends Scope */ // List all templates $templates = $this->client->call(Client::METHOD_GET, '/functions/templates', array_merge([ - 'content-type' => 'application/json', + 'content-type' => 'application/json' ], $this->getHeaders())); $this->assertEquals(200, $templates['headers']['status-code']); diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 2daab87ffa..f4cd9ca493 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -3,6 +3,7 @@ namespace Tests\E2E\Services\Functions; use Appwrite\Functions\Specification; +use Appwrite\Tests\Retry; use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; @@ -511,6 +512,7 @@ class FunctionsCustomServerTest extends Scope /** * @depends testUpdateFunction */ + #[Retry(count: 3)] public function testCancelDeploymentBuild($data): void { $functionId = $data['functionId']; diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index 031716b24b..cdb7b3e2ad 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -208,12 +208,14 @@ trait SitesBase return $deployments; } - protected function listLogs(string $siteId, mixed $params = []): mixed + protected function listLogs(string $siteId, array $queries = []): mixed { $logs = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId . '/logs', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), $params); + ], $this->getHeaders()), [ + 'queries' => $queries + ]); return $logs; } diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 43d9fc173b..c6eb50fdee 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -3,6 +3,7 @@ namespace Tests\E2E\Services\Sites; use Appwrite\Sites\Specification; +use Appwrite\Tests\Retry; use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; @@ -674,6 +675,7 @@ class SitesCustomServerTest extends Scope $this->cleanupSite($siteId); } + #[Retry(count: 3)] public function testCancelDeploymentBuild(): void { $siteId = $this->setupSite([ @@ -1675,4 +1677,74 @@ class SitesCustomServerTest extends Scope $this->cleanupSite($siteId); } + + public function testSSRLogs(): void + { + $siteId = $this->setupSite([ + 'siteId' => ID::unique(), + 'name' => 'SSR site', + 'framework' => 'astro', + 'adapter' => 'ssr', + 'buildRuntime' => 'ssr-22', + 'outputDirectory' => './dist', + 'buildCommand' => 'npm run build', + 'installCommand' => 'npm install', + 'fallbackFile' => '', + ]); + + $this->assertNotEmpty($siteId); + + $domain = $this->setupSiteDomain($siteId); + + $deploymentId = $this->setupDeployment($siteId, [ + 'code' => $this->packageSite('astro'), + 'activate' => 'true' + ]); + + $this->assertNotEmpty($deploymentId); + + $domain = $this->getSiteDomain($siteId); + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://' . $domain); + + $response = $proxyClient->call(Client::METHOD_GET, '/logs-inline'); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertStringContainsString("Inline logs printed.", $response['body']); + + $logs = $this->listLogs($siteId, [ + Query::orderDesc('$createdAt')->toString(), + Query::limit(1)->toString(), + ]); + $this->assertEquals(200, $logs['headers']['status-code']); + $this->assertStringContainsString("GET", $logs['body']['executions'][0]['requestMethod']); + $this->assertStringContainsString("/logs-inline", $logs['body']['executions'][0]['requestPath']); + $this->assertStringContainsString("Log1", $logs['body']['executions'][0]['logs']); + $this->assertStringContainsString("Log2", $logs['body']['executions'][0]['logs']); + $this->assertStringContainsString("Error1", $logs['body']['executions'][0]['errors']); + $this->assertStringContainsString("Error2", $logs['body']['executions'][0]['errors']); + $log1Id = $logs['body']['executions'][0]['$id']; + $this->assertNotEmpty($log1Id); + + $response = $proxyClient->call(Client::METHOD_GET, '/logs-action'); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertStringContainsString("Action logs printed.", $response['body']); + + $logs = $this->listLogs($siteId, [ + Query::orderDesc('$createdAt')->toString(), + Query::limit(1)->toString(), + ]); + $this->assertEquals(200, $logs['headers']['status-code']); + $this->assertStringContainsString("GET", $logs['body']['executions'][0]['requestMethod']); + $this->assertStringContainsString("/logs-action", $logs['body']['executions'][0]['requestPath']); + $this->assertStringContainsString("Log1", $logs['body']['executions'][0]['logs']); + $this->assertStringContainsString("Log2", $logs['body']['executions'][0]['logs']); + $this->assertStringContainsString("Error1", $logs['body']['executions'][0]['errors']); + $this->assertStringContainsString("Error2", $logs['body']['executions'][0]['errors']); + $log2Id = $logs['body']['executions'][0]['$id']; + $this->assertNotEmpty($log2Id); + + $this->assertNotEquals($log1Id, $log2Id); + + $this->cleanupSite($siteId); + } } diff --git a/tests/resources/sites/astro/astro.config.mjs b/tests/resources/sites/astro/astro.config.mjs index 54bee6ca84..a87942461e 100644 --- a/tests/resources/sites/astro/astro.config.mjs +++ b/tests/resources/sites/astro/astro.config.mjs @@ -1,9 +1,8 @@ import { defineConfig } from 'astro/config'; import node from '@astrojs/node'; -import 'dotenv/config'; export default defineConfig({ - output: 'server', + output: 'server', adapter: node({ mode: 'standalone' }), diff --git a/tests/resources/sites/astro/package.json b/tests/resources/sites/astro/package.json index a87c37d014..8cbcb910f5 100644 --- a/tests/resources/sites/astro/package.json +++ b/tests/resources/sites/astro/package.json @@ -10,7 +10,6 @@ }, "dependencies": { "@astrojs/node": "^9.0.2", - "astro": "^5.2.5", - "dotenv": "^16.4.7" + "astro": "^5.2.5" } } diff --git a/tests/resources/sites/astro/src/pages/logs-action.js b/tests/resources/sites/astro/src/pages/logs-action.js new file mode 100644 index 0000000000..348297a616 --- /dev/null +++ b/tests/resources/sites/astro/src/pages/logs-action.js @@ -0,0 +1,7 @@ +export async function GET(context) { + console.log("Log1"); + console.error("Error1"); + console.log("Log2"); + console.error("Error2"); + return new Response('Action logs printed.'); +} diff --git a/tests/resources/sites/astro/src/pages/logs-inline.astro b/tests/resources/sites/astro/src/pages/logs-inline.astro new file mode 100644 index 0000000000..c539142d83 --- /dev/null +++ b/tests/resources/sites/astro/src/pages/logs-inline.astro @@ -0,0 +1,18 @@ +--- +console.log("Log1"); +console.error("Error1"); +console.log("Log2"); +console.error("Error2"); +--- + + + + + + + Astro Logs + + +

Inline logs printed.

+ + diff --git a/tests/resources/sites/astro/tsconfig.json b/tests/resources/sites/astro/tsconfig.json deleted file mode 100644 index 8bf91d3bb9..0000000000 --- a/tests/resources/sites/astro/tsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "astro/tsconfigs/strict", - "include": [".astro/types.d.ts", "**/*"], - "exclude": ["dist"] -}