2022-08-04 12:14:26 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Shlinkio\Shlink;
|
|
|
|
|
2022-08-04 12:27:33 +03:00
|
|
|
use Fig\Http\Message\RequestMethodInterface;
|
2022-08-04 12:14:26 +03:00
|
|
|
use RKA\Middleware\IpAddress;
|
|
|
|
use Shlinkio\Shlink\Core\Action as CoreAction;
|
2022-08-04 12:49:33 +03:00
|
|
|
use Shlinkio\Shlink\Core\Config\EnvVars;
|
2022-08-04 12:14:26 +03:00
|
|
|
use Shlinkio\Shlink\Rest\Action;
|
|
|
|
use Shlinkio\Shlink\Rest\ConfigProvider;
|
|
|
|
use Shlinkio\Shlink\Rest\Middleware;
|
|
|
|
use Shlinkio\Shlink\Rest\Middleware\Mercure\NotConfiguredMercureErrorHandler;
|
|
|
|
|
2022-08-04 12:49:33 +03:00
|
|
|
use function sprintf;
|
|
|
|
|
2022-08-04 12:27:33 +03:00
|
|
|
// The order of the routes defined here matters. Changing it might cause path conflicts
|
2022-08-04 12:14:26 +03:00
|
|
|
return (static function (): array {
|
|
|
|
$contentNegotiationMiddleware = Middleware\ShortUrl\CreateShortUrlContentNegotiationMiddleware::class;
|
|
|
|
$dropDomainMiddleware = Middleware\ShortUrl\DropDefaultDomainFromRequestMiddleware::class;
|
|
|
|
$overrideDomainMiddleware = Middleware\ShortUrl\OverrideDomainMiddleware::class;
|
2022-08-04 12:49:33 +03:00
|
|
|
$multiSegment = (bool) EnvVars::MULTI_SEGMENT_SLUGS_ENABLED->loadFromEnv(false);
|
2022-08-04 12:14:26 +03:00
|
|
|
|
|
|
|
return [
|
|
|
|
|
|
|
|
'routes' => [
|
2022-08-04 12:27:33 +03:00
|
|
|
// Rest
|
2022-08-04 12:14:26 +03:00
|
|
|
...ConfigProvider::applyRoutesPrefix([
|
|
|
|
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,
|
|
|
|
$dropDomainMiddleware,
|
|
|
|
$overrideDomainMiddleware,
|
|
|
|
Middleware\ShortUrl\DefaultShortCodesLengthMiddleware::class,
|
|
|
|
]),
|
|
|
|
Action\ShortUrl\SingleStepCreateShortUrlAction::getRouteDef([
|
|
|
|
$contentNegotiationMiddleware,
|
|
|
|
$overrideDomainMiddleware,
|
|
|
|
]),
|
|
|
|
Action\ShortUrl\EditShortUrlAction::getRouteDef([$dropDomainMiddleware]),
|
|
|
|
Action\ShortUrl\DeleteShortUrlAction::getRouteDef([$dropDomainMiddleware]),
|
|
|
|
Action\ShortUrl\ResolveShortUrlAction::getRouteDef([$dropDomainMiddleware]),
|
|
|
|
Action\ShortUrl\ListShortUrlsAction::getRouteDef(),
|
|
|
|
|
|
|
|
// Tags
|
|
|
|
Action\Tag\ListTagsAction::getRouteDef(),
|
|
|
|
Action\Tag\TagsStatsAction::getRouteDef(),
|
|
|
|
Action\Tag\DeleteTagsAction::getRouteDef(),
|
|
|
|
Action\Tag\UpdateTagAction::getRouteDef(),
|
|
|
|
|
|
|
|
// Domains
|
|
|
|
Action\Domain\ListDomainsAction::getRouteDef(),
|
|
|
|
Action\Domain\DomainRedirectsAction::getRouteDef(),
|
|
|
|
|
|
|
|
Action\MercureInfoAction::getRouteDef([NotConfiguredMercureErrorHandler::class]),
|
2022-08-04 12:49:33 +03:00
|
|
|
], $multiSegment),
|
2022-08-04 12:14:26 +03:00
|
|
|
|
|
|
|
// Non-rest
|
|
|
|
[
|
|
|
|
'name' => CoreAction\RobotsAction::class,
|
|
|
|
'path' => '/robots.txt',
|
|
|
|
'middleware' => [
|
|
|
|
CoreAction\RobotsAction::class,
|
|
|
|
],
|
2022-08-04 12:27:33 +03:00
|
|
|
'allowed_methods' => [RequestMethodInterface::METHOD_GET],
|
2022-08-04 12:14:26 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => CoreAction\PixelAction::class,
|
2022-08-04 12:49:33 +03:00
|
|
|
'path' => sprintf('/{shortCode%s}/track', $multiSegment ? ':.+' : ''),
|
2022-08-04 12:14:26 +03:00
|
|
|
'middleware' => [
|
|
|
|
IpAddress::class,
|
|
|
|
CoreAction\PixelAction::class,
|
|
|
|
],
|
2022-08-04 12:27:33 +03:00
|
|
|
'allowed_methods' => [RequestMethodInterface::METHOD_GET],
|
2022-08-04 12:14:26 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => CoreAction\QrCodeAction::class,
|
2022-08-04 12:49:33 +03:00
|
|
|
'path' => sprintf('/{shortCode%s}/qr-code', $multiSegment ? ':.+' : ''),
|
2022-08-04 12:14:26 +03:00
|
|
|
'middleware' => [
|
|
|
|
CoreAction\QrCodeAction::class,
|
|
|
|
],
|
2022-08-04 12:27:33 +03:00
|
|
|
'allowed_methods' => [RequestMethodInterface::METHOD_GET],
|
2022-08-04 12:14:26 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => CoreAction\RedirectAction::class,
|
2022-08-04 12:49:33 +03:00
|
|
|
'path' => sprintf('/{shortCode%s}', $multiSegment ? ':.+' : ''),
|
2022-08-04 12:14:26 +03:00
|
|
|
'middleware' => [
|
|
|
|
IpAddress::class,
|
|
|
|
CoreAction\RedirectAction::class,
|
|
|
|
],
|
2022-08-04 12:27:33 +03:00
|
|
|
'allowed_methods' => [RequestMethodInterface::METHOD_GET],
|
2022-08-04 12:14:26 +03:00
|
|
|
],
|
|
|
|
],
|
|
|
|
|
|
|
|
];
|
|
|
|
})();
|