shlinkio / shlink

The definitive self-hosted URL shortener
https://shlink.io
MIT License
3.28k stars 261 forks source link

Setting base_url_redirect_to causes a 500 error when visiting the base url #665

Closed jpatters closed 4 years ago

jpatters commented 4 years ago

How Shlink is set-up

Summary

Setting base_url_redirect_to causes a 500 error when visiting the base url.

Current behavior

Next Laminas\ServiceManager\Exception\ServiceNotCreatedException: Service with name "Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions" could not be created. Reason: The option "base_path" does not have a callable "setBasePath" ("setbasepath") setter method which must be defined in /etc/shlink/vendor/laminas/laminas-servicemanager/src/ServiceManager.php:772
Stack trace:
#0 /etc/shlink/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(201): Laminas\ServiceManager\ServiceManager->doCreate('Shlinkio\\Shlink...')
#1 [internal function]: Laminas\ServiceManager\ServiceManager->get('Shlinkio\\Shlink...')
#2 /etc/shlink/vendor/laminas/laminas-servicemanager/src/AbstractFactory/ConfigAbstractFactory.php(69): array_map(Array, Array)
#3 /etc/shlink/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(765): Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory->__invoke(Object(Laminas\ServiceManager\ServiceManager), 'Shlinkio\\Shlink...', NULL)
#4 /etc/shlink/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(201): Laminas\ServiceManager\ServiceManager->doCreate('Shlinkio\\Shlink...')
#5 /etc/shlink/vendor/mezzio/mezzio/src/MiddlewareContainer.php(64): Laminas\ServiceManager\ServiceManager->get('Shlinkio\\Shlink...')
#6 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(46): Mezzio\MiddlewareContainer->get('Shlinkio\\Shlink...')
#7 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#8 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(84): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
#9 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#10 /etc/shlink/vendor/laminas/laminas-stratigility/src/Middleware/PathMiddlewareDecorator.php(43): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
...

I can post more of the stack trace if needed.

Expected behavior

It should redirect to the domain I set base_url_redirect_to to.

I believe the issue is here: https://github.com/shlinkio/shlink/blob/master/module/Core/src/Config/SimplifiedConfigParser.php#L27

It looks like maybe that line should be. But I have only started looking at this today:

'base_url_redirect_to' => ['not_found_redirects', 'base_url'],
acelaya commented 4 years ago

Hello @jpatters

You are completely right. It should be base_url, not base_path. Thanks for looking at it.

Do you want to provide a pull request to fix it? I can do it if you prefer, but since you already found the issue, it should be a quick fix. Up to you.

In the meantime, you can workaround this by not passing this config option and instead passing it as the BASE_URL_REDIRECT_TO env var.

jpatters commented 4 years ago

PR open. Glad I could be of assistance.