From 6ebd90d8dbf71d61e30cf3c6f30d3a417af9f33e Mon Sep 17 00:00:00 2001 From: Andrew Killen Date: Tue, 12 Mar 2024 11:56:10 +0100 Subject: [PATCH 1/3] added ability to get api_url from environement.json with a fallback to Pro url for API calls if not found. Easier for development. --- src/Servebolt/Helpers/Helpers.php | 15 ++++++++++++++- src/Servebolt/ServeboltOptimizer.php | 10 +++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Servebolt/Helpers/Helpers.php b/src/Servebolt/Helpers/Helpers.php index c50d5543..2b8a24fd 100644 --- a/src/Servebolt/Helpers/Helpers.php +++ b/src/Servebolt/Helpers/Helpers.php @@ -356,6 +356,20 @@ function getSiteId(): ?string * * @return mixed|null */ +function getApiUrlFromEnvFile(): ?string +{ + $env = \Servebolt\Optimizer\Utils\EnvFile\Reader::getInstance(); + if ($env->api_url) { + return $env->api_url . '/v1/'; + } + return "https://api.servebolt.io/v1/"; +} + +/** + * Get site API url from Env-file. + * + * @return mixed|null + */ function getSiteIdFromEnvFile(): ?string { $env = \Servebolt\Optimizer\Utils\EnvFile\Reader::getInstance(); @@ -364,7 +378,6 @@ function getSiteIdFromEnvFile(): ?string } return null; } - /** * Get site ID from the webroot folder path. * diff --git a/src/Servebolt/ServeboltOptimizer.php b/src/Servebolt/ServeboltOptimizer.php index e0b1418f..67f7275e 100644 --- a/src/Servebolt/ServeboltOptimizer.php +++ b/src/Servebolt/ServeboltOptimizer.php @@ -35,6 +35,7 @@ use function Servebolt\Optimizer\Helpers\isHostedAtServebolt; use function Servebolt\Optimizer\Helpers\isTesting; use function Servebolt\Optimizer\Helpers\envFileFailureHandling; +use function Servebolt\Optimizer\Helpers\getApiUrlFromEnvFile; /** * Class ServeboltOptimizer @@ -46,7 +47,7 @@ class ServeboltOptimizer * Boot the plugin. */ public static function boot() - { + { // Handle activation/deactivation new PluginActiveStateHandling; @@ -70,6 +71,7 @@ public static function boot() WpMenuOptimizer::init(); if (isHostedAtServebolt()) { + // ACD Init AcceleratedDomains::init(); @@ -79,6 +81,12 @@ public static function boot() // Init environment file reader EnvFileReader::getInstance(); + // Now settings the API URI based on the environment file->api_url. + // it always defaults to the Prod api if the environment file value is not present. + if(!defined('SERVEBOLT_API_BASE_URI')) { + define('SERVEBOLT_API_BASE_URI', getApiUrlFromEnvFile()); + } + } new AddCacheTagsHeaders; From d82b3c398cac0a34e6539281a991c7efbb768da0 Mon Sep 17 00:00:00 2001 From: Andrew Killen Date: Tue, 12 Mar 2024 15:39:57 +0100 Subject: [PATCH 2/3] renamed constant --- src/Servebolt/ServeboltOptimizer.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Servebolt/ServeboltOptimizer.php b/src/Servebolt/ServeboltOptimizer.php index 67f7275e..85e6be84 100644 --- a/src/Servebolt/ServeboltOptimizer.php +++ b/src/Servebolt/ServeboltOptimizer.php @@ -83,10 +83,9 @@ public static function boot() // Now settings the API URI based on the environment file->api_url. // it always defaults to the Prod api if the environment file value is not present. - if(!defined('SERVEBOLT_API_BASE_URI')) { - define('SERVEBOLT_API_BASE_URI', getApiUrlFromEnvFile()); + if(!defined('SERVEBOLT_SDK_BASE_URI')) { + define('SERVEBOLT_SDK_BASE_URI', getApiUrlFromEnvFile()); } - } new AddCacheTagsHeaders; From eceb372b199b312f24f3c957db01fb3f41b3cc2b Mon Sep 17 00:00:00 2001 From: Andrew Killen Date: Wed, 13 Mar 2024 08:46:19 +0100 Subject: [PATCH 3/3] pre-release documentation --- README.md | 3 +++ Readme.txt | 3 +++ servebolt-optimizer.php | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f9682c78..41e955a4 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,9 @@ If you want to build a local production-ready version of the plugin you can run ## Changelog +#### 3.5.30 +* When on Servebolt the plugin now checks the environement.json file to see if the key `api_url` exists. If its there it will use that, if not it will continue to use the pre-defined url for communication with the Servebolt API. + #### 3.5.29 * adapted cache tags prefix to be unique: Chosing between the shortest of bolt_id plus environment_id as one string, the domain name without dots as the other string. diff --git a/Readme.txt b/Readme.txt index 3eb17a8b..2fcfb9c3 100644 --- a/Readme.txt +++ b/Readme.txt @@ -98,6 +98,9 @@ If you're a Servebolt client, please reach out to our Support Team and we'll be == Changelog == += 3.5.30 = +* When on Servebolt the plugin now checks the environement.json file to see if the key `api_url` exists. If its there it will use that, if not it will continue to use the pre-defined url for communication with the Servebolt API. + = 3.5.29 = * adapted cache tags prefix to be unique: Chosing between the shortest of bolt_id plus environment_id as one string, the domain name without dots as the other string. diff --git a/servebolt-optimizer.php b/servebolt-optimizer.php index 53e74987..89e9b696 100644 --- a/servebolt-optimizer.php +++ b/servebolt-optimizer.php @@ -1,7 +1,7 @@