feat: make server root configurable

This commit is contained in:
Emmanuel BENOîT 2025-01-05 19:04:03 +01:00
parent 5320ba3e11
commit b21bf52e4d
Signed by: Emmanuel BENOîT
SSH key fingerprint: SHA256:l7PFUUF5TCDsvYeQC9OnTNz08dFY7Fvf4Hv3neIqYpg

View file

@ -10,10 +10,7 @@ abstract class Page
public function __construct( )
{
$this->baseURL = dirname( $_SERVER[ 'SCRIPT_NAME' ] );
if ( $this->baseURL == '/' ) {
$this->baseURL = '';
}
$this->baseURL = rtrim(dirname( $_SERVER[ 'SCRIPT_NAME' ] ), '/');
}
public final function addController( Controller $controller )
@ -29,6 +26,16 @@ abstract class Page
return $this;
}
public final function getServerRoot( )
{
$root = Loader::PackageConfig( 'core' )->get( 'pages/baseURL' , null , false );
if (is_null($root)) {
$root = ( ( $_SERVER[ 'HTTPS' ] ?: false ) ? 'https' : 'http' )
. '://' . $_SERVER[ 'HTTP_HOST' ];
}
return rtrim($root, '/');
}
public final function getBaseURL( )
{
return $this->baseURL;
@ -55,8 +62,7 @@ abstract class Page
if ( $rc[0] != '/' ) {
$rc = $this->baseURL . '/' . $rc;
}
$rc = ( ( array_key_exists( 'HTTPS' , $_SERVER ) && $_SERVER[ 'HTTPS' ] ) ? 'https' : 'http' ) . '://' . $_SERVER[ 'SERVER_NAME' ]
. ':' . $_SERVER[ 'SERVER_PORT' ] . $rc;
$rc = $this->getServerRoot() . $rc;
header( "Location: $rc" );
$rv = true;
}