]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/front/ShaarliMiddleware.php
Explicitly define base and asset path in templates
[github/shaarli/Shaarli.git] / application / front / ShaarliMiddleware.php
index fa6c64671d56b9db1ee43cd4c13f71ef15f30958..47aa61bbfb6f9d05f6dff325501d45d3b4b82b81 100644 (file)
@@ -3,7 +3,8 @@
 namespace Shaarli\Front;
 
 use Shaarli\Container\ShaarliContainer;
-use Shaarli\Front\Exception\ShaarliException;
+use Shaarli\Front\Exception\ShaarliFrontException;
+use Shaarli\Front\Exception\UnauthorizedException;
 use Slim\Http\Request;
 use Slim\Http\Response;
 
@@ -38,8 +39,10 @@ class ShaarliMiddleware
     public function __invoke(Request $request, Response $response, callable $next)
     {
         try {
+            $this->container->basePath = rtrim($request->getUri()->getBasePath(), '/');
+
             $response = $next($request, $response);
-        } catch (ShaarliException $e) {
+        } catch (ShaarliFrontException $e) {
             $this->container->pageBuilder->assign('message', $e->getMessage());
             if ($this->container->conf->get('dev.debug', false)) {
                 $this->container->pageBuilder->assign(
@@ -50,6 +53,8 @@ class ShaarliMiddleware
 
             $response = $response->withStatus($e->getCode());
             $response = $response->write($this->container->pageBuilder->render('error'));
+        } catch (UnauthorizedException $e) {
+            return $response->withRedirect($request->getUri()->getBasePath() . '/login');
         }
 
         return $response;