Provide basePath support (#309)
* Provide basePath support To be able to serve the application via a reverse proxy in a subfolder smarty needs to be aware of the basepath if any. * Provide basepath support via X-Forwarded headers * Fix warnings * Review adjustments * Provide support X-Forwarded-Host header * Use $uri in view factory directly * Use middleware to set basepath from X-Forwarded-Path header * Fix invalid type hint in RouterPathMiddleware * Add "X-Forwarded-Host" to README
This commit is contained in:
parent
234ecc2c6d
commit
c5298dd24b
4 changed files with 71 additions and 2 deletions
42
classes/RouterPathMiddleware.php
Normal file
42
classes/RouterPathMiddleware.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Alltube;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Slim\Http\Request;
|
||||
use Slim\Http\Response;
|
||||
use Slim\Router;
|
||||
|
||||
/**
|
||||
* Class RouterPathMiddleware
|
||||
* @package Alltube
|
||||
*/
|
||||
class RouterPathMiddleware
|
||||
{
|
||||
/**
|
||||
* @var Router
|
||||
*/
|
||||
private $router;
|
||||
|
||||
/**
|
||||
* RouterPathMiddleware constructor.
|
||||
* @param ContainerInterface $container
|
||||
*/
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->router = $container->get('router');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Response $response
|
||||
* @param callable $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function __invoke(Request $request, Response $response, callable $next)
|
||||
{
|
||||
$this->router->setBasePath(current($request->getHeader('X-Forwarded-Path')));
|
||||
|
||||
return $next($request, $response);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue