diff --git a/UPGRADE.md b/UPGRADE.md index bce1bdde..6bef9dbc 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -76,7 +76,7 @@ These routes have been removed, but have a direct replacement: * `/qr/{shortCode}[/{size}]` -> `/{shortCode}/qr-code[/{size}]` * `PUT /rest/v{version}/short-urls/{shortCode}` -> `PATCH /rest/v{version}/short-urls/{shortCode}` -When using the old ones, a 404 status will me returned now. +When using the old ones, a 404 status will be returned now. ### Removed command and route aliases diff --git a/config/autoload/middleware-pipeline.global.php b/config/autoload/middleware-pipeline.global.php index 9c0e2978..c628c4fd 100644 --- a/config/autoload/middleware-pipeline.global.php +++ b/config/autoload/middleware-pipeline.global.php @@ -68,7 +68,6 @@ return [ // This middleware is in front of tracking actions explicitly. Putting here for orphan visits tracking IpAddress::class, Core\ErrorHandler\NotFoundTypeResolverMiddleware::class, - // TODO MultiSegmentSlugRedirectMiddleware Core\ShortUrl\Middleware\ExtraPathRedirectMiddleware::class, Core\ErrorHandler\NotFoundTrackerMiddleware::class, Core\ErrorHandler\NotFoundRedirectHandler::class, diff --git a/config/config.php b/config/config.php index 3dad2105..19e3a82d 100644 --- a/config/config.php +++ b/config/config.php @@ -36,11 +36,12 @@ return (new ConfigAggregator\ConfigAggregator([ Importer\ConfigProvider::class, IpGeolocation\ConfigProvider::class, EventDispatcher\ConfigProvider::class, - Core\ConfigProvider::class, CLI\ConfigProvider::class, - Rest\ConfigProvider::class, + Rest\ConfigProvider::class, // Load rest before Core, to prevent conflicting routes when multi-segment is enabled + Core\ConfigProvider::class, new ConfigAggregator\PhpFileProvider('config/autoload/{{,*.}global,{,*.}local}.php'), $isTestEnv + // TODO Test routes must be loaded before core config ? new ConfigAggregator\PhpFileProvider('config/test/*.global.php') : new ConfigAggregator\ArrayProvider([]), ], 'data/cache/app_config.php', [ diff --git a/module/Core/config/routes.config.php b/module/Core/config/routes.config.php index 07e33c73..bb7e94f5 100644 --- a/module/Core/config/routes.config.php +++ b/module/Core/config/routes.config.php @@ -17,18 +17,9 @@ return [ ], 'allowed_methods' => [RequestMethod::METHOD_GET], ], - [ - 'name' => Action\RedirectAction::class, - 'path' => '/{shortCode}', - 'middleware' => [ - IpAddress::class, - Action\RedirectAction::class, - ], - 'allowed_methods' => [RequestMethod::METHOD_GET], - ], [ 'name' => Action\PixelAction::class, - 'path' => '/{shortCode}/track', + 'path' => '/{shortCode:.+}/track', 'middleware' => [ IpAddress::class, Action\PixelAction::class, @@ -37,12 +28,21 @@ return [ ], [ 'name' => Action\QrCodeAction::class, - 'path' => '/{shortCode}/qr-code', + 'path' => '/{shortCode:.+}/qr-code', 'middleware' => [ Action\QrCodeAction::class, ], 'allowed_methods' => [RequestMethod::METHOD_GET], ], + [ + 'name' => Action\RedirectAction::class, + 'path' => '/{shortCode:.+}', + 'middleware' => [ + IpAddress::class, + Action\RedirectAction::class, + ], + 'allowed_methods' => [RequestMethod::METHOD_GET], + ], ], ]; diff --git a/module/Rest/config/routes.config.php b/module/Rest/config/routes.config.php index f318664f..dbc10ba8 100644 --- a/module/Rest/config/routes.config.php +++ b/module/Rest/config/routes.config.php @@ -16,6 +16,14 @@ return (static function (): array { 'routes' => [ Action\HealthAction::getRouteDef(), + // Visits + Action\Visit\ShortUrlVisitsAction::getRouteDef([$dropDomainMiddleware]), + Action\Visit\TagVisitsAction::getRouteDef(), + Action\Visit\DomainVisitsAction::getRouteDef(), + Action\Visit\GlobalVisitsAction::getRouteDef(), + Action\Visit\OrphanVisitsAction::getRouteDef(), + Action\Visit\NonOrphanVisitsAction::getRouteDef(), + // Short URLs Action\ShortUrl\CreateShortUrlAction::getRouteDef([ $contentNegotiationMiddleware, @@ -32,14 +40,6 @@ return (static function (): array { Action\ShortUrl\ResolveShortUrlAction::getRouteDef([$dropDomainMiddleware]), Action\ShortUrl\ListShortUrlsAction::getRouteDef(), - // Visits - Action\Visit\ShortUrlVisitsAction::getRouteDef([$dropDomainMiddleware]), - Action\Visit\TagVisitsAction::getRouteDef(), - Action\Visit\DomainVisitsAction::getRouteDef(), - Action\Visit\GlobalVisitsAction::getRouteDef(), - Action\Visit\OrphanVisitsAction::getRouteDef(), - Action\Visit\NonOrphanVisitsAction::getRouteDef(), - // Tags Action\Tag\ListTagsAction::getRouteDef(), Action\Tag\TagsStatsAction::getRouteDef(), diff --git a/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php b/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php index 8059e5ab..40b03b6e 100644 --- a/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php @@ -14,7 +14,7 @@ use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware; class DeleteShortUrlAction extends AbstractRestAction { - protected const ROUTE_PATH = '/short-urls/{shortCode}'; + protected const ROUTE_PATH = '/short-urls/{shortCode:.+}'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_DELETE]; public function __construct(private DeleteShortUrlServiceInterface $deleteShortUrlService) diff --git a/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php b/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php index 87c21aec..d82aef3e 100644 --- a/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php @@ -16,8 +16,8 @@ use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware; class EditShortUrlAction extends AbstractRestAction { - protected const ROUTE_PATH = '/short-urls/{shortCode}'; - protected const ROUTE_ALLOWED_METHODS = [self::METHOD_PATCH, self::METHOD_PUT]; + protected const ROUTE_PATH = '/short-urls/{shortCode:.+}'; + protected const ROUTE_ALLOWED_METHODS = [self::METHOD_PATCH]; public function __construct( private ShortUrlServiceInterface $shortUrlService, diff --git a/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php b/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php index aae1a895..66719cba 100644 --- a/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php @@ -15,7 +15,7 @@ use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware; class ResolveShortUrlAction extends AbstractRestAction { - protected const ROUTE_PATH = '/short-urls/{shortCode}'; + protected const ROUTE_PATH = '/short-urls/{shortCode:.+}'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; public function __construct( diff --git a/module/Rest/src/Action/Visit/ShortUrlVisitsAction.php b/module/Rest/src/Action/Visit/ShortUrlVisitsAction.php index 5496ba35..45254f18 100644 --- a/module/Rest/src/Action/Visit/ShortUrlVisitsAction.php +++ b/module/Rest/src/Action/Visit/ShortUrlVisitsAction.php @@ -18,7 +18,7 @@ class ShortUrlVisitsAction extends AbstractRestAction { use PagerfantaUtilsTrait; - protected const ROUTE_PATH = '/short-urls/{shortCode}/visits'; + protected const ROUTE_PATH = '/short-urls/{shortCode:.+}/visits'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; public function __construct(private VisitsStatsHelperInterface $visitsHelper)