1
0
mirror of https://github.com/typemill/typemill.git synced 2025-08-11 08:34:45 +02:00

Add support for schemeless base_url

This commit is contained in:
Mahdi
2023-06-04 14:51:22 +10:00
parent 34e02fac14
commit 367a486b20
12 changed files with 51 additions and 22 deletions

View File

@@ -8,33 +8,40 @@ use Slim\Http\Response;
class assetMiddleware
{
protected $view;
protected $c;
public function __construct($container)
{
# $this->view = $view;
$this->container = $container;
}
public function __invoke(Request $request, Response $response, $next)
{
protected $view;
protected $c;
protected $settings;
public function __construct($container, $settings)
{
# $this->view = $view;
$this->container = $container;
$this->settings = $settings;
}
public function __invoke(Request $request, Response $response, $next)
{
# get the uri after proxy detection
$uri = $request->getUri()->withUserInfo('');
# get the uri after proxy detection
$uri = $request->getUri()->withUserInfo('');
if(isset($this->settings['schemelessbaseurl']) && $this->settings['schemelessbaseurl'])
{
$uri = $uri->withScheme('');
}
# update the asset object in the container (for plugins) with the new url
$this->container->assets->setBaseUrl($uri->getBaseUrl());
# add the asset object to twig-frontend for themes
$this->container['view']->getEnvironment()->addGlobal('assets', $this->container['assets']);
# use {{ base_url() }} in twig templates
# add the asset object to twig-frontend for themes
$this->container['view']->getEnvironment()->addGlobal('assets', $this->container['assets']);
# use {{ base_url() }} in twig templates
$this->container['view']['base_url'] = $uri->getBaseUrl();
$this->container['view']['current_url'] = $uri->getPath();
$response = $next($request, $response);
return $response;
}
$response = $next($request, $response);
return $response;
}
}