mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-14 04:00:57 +03:00
Ensured the health action is registered bit with and without version
This commit is contained in:
parent
96eb6a80e1
commit
36d5e057d0
3 changed files with 12 additions and 6 deletions
|
@ -12,6 +12,7 @@ return [
|
|||
'routes_whitelist' => [
|
||||
Action\HealthAction::class,
|
||||
Action\ShortUrl\SingleStepCreateShortUrlAction::class,
|
||||
ConfigProvider::UNVERSIONED_HEALTH_ENDPOINT_NAME,
|
||||
],
|
||||
|
||||
'plugins' => [
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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']);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue