diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 771dd0e6a5..a2eefb3355 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -3552,7 +3552,8 @@ App::post('/v1/messaging/messages/push') throw new Exception(Exception::STORAGE_FILE_TYPE_UNSUPPORTED); } - $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https'; + $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https'; + $endpoint = "$protocol://{$platform['apiHostname']}/v1"; $scheduleTime = $currentScheduledAt ?? $scheduledAt; if (!\is_null($scheduleTime)) { @@ -3572,7 +3573,7 @@ App::post('/v1/messaging/messages/push') $image = [ 'bucketId' => $bucket->getId(), 'fileId' => $file->getId(), - 'url' => "{$platform['endpoint']}/storage/buckets/{$bucket->getId()}/files/{$file->getId()}/push?project={$project->getId()}&jwt={$jwt}", + 'url' => "{$endpoint}/storage/buckets/{$bucket->getId()}/files/{$file->getId()}/push?project={$project->getId()}&jwt={$jwt}", ]; } @@ -4562,10 +4563,13 @@ App::patch('/v1/messaging/messages/push/:messageId') 'projectId' => $project->getId(), ]); + $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https'; + $endpoint = "$protocol://{$platform['apiHostname']}/v1"; + $pushData['image'] = [ 'bucketId' => $bucket->getId(), 'fileId' => $file->getId(), - 'url' => "{$platform['endpoint']}/storage/buckets/{$bucket->getId()}/files/{$file->getId()}/push?project={$project->getId()}&jwt={$jwt}", + 'url' => "{$endpoint}/storage/buckets/{$bucket->getId()}/files/{$file->getId()}/push?project={$project->getId()}&jwt={$jwt}", ]; } diff --git a/app/controllers/general.php b/app/controllers/general.php index 30bb46ed9a..996b1dce98 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -458,10 +458,13 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw $vars[$var->getAttribute('key')] = $var->getAttribute('value', ''); } + $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https'; + $endpoint = "$protocol://{$platform['apiHostname']}/v1"; + // Appwrite vars if ($type === 'function') { $vars = \array_merge($vars, [ - 'APPWRITE_FUNCTION_API_ENDPOINT' => $platform['endpoint'], + 'APPWRITE_FUNCTION_API_ENDPOINT' => $endpoint, 'APPWRITE_FUNCTION_ID' => $resource->getId(), 'APPWRITE_FUNCTION_NAME' => $resource->getAttribute('name'), 'APPWRITE_FUNCTION_DEPLOYMENT' => $deployment->getId(), @@ -473,7 +476,7 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw ]); } elseif ($type === 'site') { $vars = \array_merge($vars, [ - 'APPWRITE_SITE_API_ENDPOINT' => $platform['endpoint'], + 'APPWRITE_SITE_API_ENDPOINT' => $endpoint, 'APPWRITE_SITE_ID' => $resource->getId(), 'APPWRITE_SITE_NAME' => $resource->getAttribute('name'), 'APPWRITE_SITE_DEPLOYMENT' => $deployment->getId(), diff --git a/app/init/resources.php b/app/init/resources.php index e40a6a8167..99476c695f 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -164,21 +164,9 @@ App::setResource('queueForStatsResources', function (Publisher $publisher) { /** * Platform configuration */ -App::setResource('platform', function (Request $request) { - $platform = Config::getParam('platform', []); - $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https'; - - $port = ''; - if ($request->getPort() === '443' && $protocol !== 'https') { - $port = ':443'; - } - if ($request->getPort() === '80' && $protocol !== 'http') { - $port = ':80'; - } - $platform['endpoint'] = "$protocol://{$platform['apiHostname']}{$port}/v1"; - - return $platform; -}, ['request']); +App::setResource('platform', function () { + return Config::getParam('platform', []); +}, []); /** * List of allowed request hostnames for the request. diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index ce06be380d..81f55ba829 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -368,9 +368,12 @@ class Create extends Base $vars[$var->getAttribute('key')] = $var->getAttribute('value', ''); } + $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https'; + $endpoint = "$protocol://{$platform['apiHostname']}/v1"; + // Appwrite vars $vars = \array_merge($vars, [ - 'APPWRITE_FUNCTION_API_ENDPOINT' => $platform['endpoint'], + 'APPWRITE_FUNCTION_API_ENDPOINT' => $endpoint, 'APPWRITE_FUNCTION_ID' => $functionId, 'APPWRITE_FUNCTION_NAME' => $function->getAttribute('name'), 'APPWRITE_FUNCTION_DEPLOYMENT' => $deployment->getId(), diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index a560c5384e..1e288c8df5 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -636,11 +636,14 @@ class Builds extends Action 'APPWRITE_VCS_ROOT_DIRECTORY' => $deployment->getAttribute('providerRootDirectory', ''), ]); + $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https'; + $endpoint = "$protocol://{$platform['apiHostname']}/v1"; + switch ($resource->getCollection()) { case 'functions': $vars = [ ...$vars, - 'APPWRITE_FUNCTION_API_ENDPOINT' => $platform['endpoint'], + 'APPWRITE_FUNCTION_API_ENDPOINT' => $endpoint, 'APPWRITE_FUNCTION_API_KEY' => API_KEY_DYNAMIC . '_' . $apiKey, 'APPWRITE_FUNCTION_ID' => $resource->getId(), 'APPWRITE_FUNCTION_NAME' => $resource->getAttribute('name'), @@ -655,7 +658,7 @@ class Builds extends Action case 'sites': $vars = [ ...$vars, - 'APPWRITE_SITE_API_ENDPOINT' => $platform['endpoint'], + 'APPWRITE_SITE_API_ENDPOINT' => $endpoint, 'APPWRITE_SITE_API_KEY' => API_KEY_DYNAMIC . '_' . $apiKey, 'APPWRITE_SITE_ID' => $resource->getId(), 'APPWRITE_SITE_NAME' => $resource->getAttribute('name'), diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index 4922ce0372..d962ddc8a8 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -87,7 +87,7 @@ class Functions extends Action $events = $payload['events'] ?? []; $data = $payload['body'] ?? ''; $eventData = $payload['payload'] ?? ''; - $platform = $payload['platform'] ?? ''; + $platform = $payload['platform'] ?? Config::getParam('platform', []); $function = new Document($payload['function'] ?? []); $functionId = $payload['functionId'] ?? ''; $user = new Document($payload['user'] ?? []); @@ -491,9 +491,12 @@ class Functions extends Action $vars[$var->getAttribute('key')] = $var->getAttribute('value', ''); } + $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https'; + $endpoint = "$protocol://{$platform['apiHostname']}/v1"; + // Appwrite vars $vars = \array_merge($vars, [ - 'APPWRITE_FUNCTION_API_ENDPOINT' => $platform['endpoint'], + 'APPWRITE_FUNCTION_API_ENDPOINT' => $endpoint, 'APPWRITE_FUNCTION_ID' => $functionId, 'APPWRITE_FUNCTION_NAME' => $function->getAttribute('name'), 'APPWRITE_FUNCTION_DEPLOYMENT' => $deploymentId,