From 36d5e057d02e0bd9ad25c22a673ecbe4e4a12016 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 6 Jan 2020 23:32:43 +0100 Subject: [PATCH] Ensured the health action is registered bit with and without version --- module/Rest/config/auth.config.php | 1 + module/Rest/src/ConfigProvider.php | 14 +++++++++----- module/Rest/test/ConfigProviderTest.php | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/module/Rest/config/auth.config.php b/module/Rest/config/auth.config.php index dd0d5369..99141364 100644 --- a/module/Rest/config/auth.config.php +++ b/module/Rest/config/auth.config.php @@ -12,6 +12,7 @@ return [ 'routes_whitelist' => [ Action\HealthAction::class, Action\ShortUrl\SingleStepCreateShortUrlAction::class, + ConfigProvider::UNVERSIONED_HEALTH_ENDPOINT_NAME, ], 'plugins' => [ diff --git a/module/Rest/src/ConfigProvider.php b/module/Rest/src/ConfigProvider.php index b94991ca..98ad8b4c 100644 --- a/module/Rest/src/ConfigProvider.php +++ b/module/Rest/src/ConfigProvider.php @@ -13,6 +13,7 @@ class ConfigProvider { private const ROUTES_PREFIX = '/rest/v{version:1|2}'; private const UNVERSIONED_ROUTES_PREFIX = '/rest'; + public const UNVERSIONED_HEALTH_ENDPOINT_NAME = 'unversioned_health'; private Closure $loadConfig; @@ -34,11 +35,14 @@ class ConfigProvider // Prepend the routes prefix to every path foreach ($routes as $key => $route) { ['path' => $path] = $route; - $routes[$key]['path'] = sprintf( - '%s%s', - $path === '/health' ? self::UNVERSIONED_ROUTES_PREFIX : self::ROUTES_PREFIX, - $path, - ); + $routes[$key]['path'] = sprintf('%s%s', self::ROUTES_PREFIX, $path); + + // Also append the health route so that it works without version + if ($path === '/health') { + $route['path'] = sprintf('%s%s', self::UNVERSIONED_ROUTES_PREFIX, $path); + $route['name'] = self::UNVERSIONED_HEALTH_ENDPOINT_NAME; + $routes[] = $route; + } } return $config; diff --git a/module/Rest/test/ConfigProviderTest.php b/module/Rest/test/ConfigProviderTest.php index 80919c30..48c71716 100644 --- a/module/Rest/test/ConfigProviderTest.php +++ b/module/Rest/test/ConfigProviderTest.php @@ -43,7 +43,8 @@ class ConfigProviderTest extends TestCase ['path' => '/rest/v{version:1|2}/foo'], ['path' => '/rest/v{version:1|2}/bar'], ['path' => '/rest/v{version:1|2}/baz/foo'], - ['path' => '/rest/health'], + ['path' => '/rest/v{version:1|2}/health'], + ['path' => '/rest/health', 'name' => ConfigProvider::UNVERSIONED_HEALTH_ENDPOINT_NAME], ], $config['routes']); } }