Added support for multi-segment slugs

This commit is contained in:
Alejandro Celaya 2022-08-03 19:32:59 +02:00
parent a570ce202a
commit fdd3e24967
9 changed files with 28 additions and 28 deletions

View file

@ -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

View file

@ -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,

View file

@ -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', [

View file

@ -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],
],
],
];

View file

@ -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(),

View file

@ -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)

View file

@ -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,

View file

@ -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(

View file

@ -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)