Some extra minor improvements

This commit is contained in:
Alejandro Celaya 2019-11-02 19:08:07 +01:00
parent 7030138ff4
commit 9abaa243e0
4 changed files with 9 additions and 13 deletions

View file

@ -133,7 +133,9 @@ docker run \
-e DISABLE_TRACK_PARAM="no-track" \
-e DELETE_SHORT_URL_THRESHOLD=30 \
-e VALIDATE_URLS=false \
-e "NOT_FOUND_REDIRECT_TO=https://www.google.com" \
-e "INVALID_SHORT_URL_REDIRECT_TO=https://my-landing-page.com" \
-e "REGULAR_404_REDIRECT_TO=https://my-landing-page.com" \
-e "BASE_URL_REDIRECT_TO=https://my-landing-page.com" \
-e "REDIS_SERVERS=tcp://172.20.0.1:6379,tcp://172.20.0.2:6379" \
-e "BASE_PATH=/my-campaign" \
shlinkio/shlink

View file

@ -7,14 +7,10 @@ namespace Shlinkio\Shlink\Core\Action;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Core\Options;
use Zend\Diactoros\Response\RedirectResponse;
class RedirectAction extends AbstractTrackingAction
{
/** @var Options\NotFoundRedirectOptions */
private $redirectOptions;
protected function createSuccessResp(string $longUrl): Response
{
// Return a redirect response to the long URL.

View file

@ -23,8 +23,8 @@ use function rtrim;
class NotFoundHandler implements RequestHandlerInterface
{
public const NOT_FOUND_ERROR_TEMPLATE = 'ShlinkCore::error/404';
public const INVALID_SHORT_CODE_ERROR_TEMPLATE = 'ShlinkCore::invalid-short-code';
public const NOT_FOUND_TEMPLATE = 'ShlinkCore::error/404';
public const INVALID_SHORT_CODE_TEMPLATE = 'ShlinkCore::invalid-short-code';
/** @var TemplateRendererInterface */
private $renderer;
@ -72,10 +72,8 @@ class NotFoundHandler implements RequestHandlerInterface
], $status);
}
$notFoundTemplate = $routeResult->isFailure()
? self::NOT_FOUND_ERROR_TEMPLATE
: self::INVALID_SHORT_CODE_ERROR_TEMPLATE;
return new Response\HtmlResponse($this->renderer->render($notFoundTemplate), $status);
$template = $routeResult->isFailure() ? self::NOT_FOUND_TEMPLATE : self::INVALID_SHORT_CODE_TEMPLATE;
return new Response\HtmlResponse($this->renderer->render($template), $status);
}
private function createRedirectResponse(RouteResult $routeResult, UriInterface $uri): ?ResponseInterface

View file

@ -130,13 +130,13 @@ class NotFoundHandlerTest extends TestCase
{
$request = ServerRequestFactory::fromGlobals();
yield [$request, NotFoundHandler::NOT_FOUND_ERROR_TEMPLATE];
yield [$request, NotFoundHandler::NOT_FOUND_TEMPLATE];
yield [
$request->withAttribute(
RouteResult::class,
RouteResult::fromRoute(new Route('', $this->prophesize(MiddlewareInterface::class)->reveal()))
),
NotFoundHandler::INVALID_SHORT_CODE_ERROR_TEMPLATE,
NotFoundHandler::INVALID_SHORT_CODE_TEMPLATE,
];
}
}