Handling subdir assets

This commit is contained in:
Pablo Ferreiro 2022-01-03 14:18:16 +01:00
parent b33c35db27
commit 5b75dd84f4
No known key found for this signature in database
GPG key ID: 41FBCE65B779FA24
5 changed files with 13 additions and 5 deletions

View file

@ -8,6 +8,10 @@ use Steampixel\Route;
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
function getSubdir(): string {
return $_ENV['APP_SUBDIR'] ? $_ENV['APP_SUBDIR'] : '/';
}
function getApi(array $proxy_elements): \Sovit\TikTok\Api {
$options = [];
// Proxy config
@ -23,6 +27,11 @@ function getApi(array $proxy_elements): \Sovit\TikTok\Api {
function getLatte(): \Latte\Engine {
$latte = new Latte\Engine;
$latte->setTempDirectory('./cache/views');
$latte->addFunction('assets', function (string $name, string $type) {
$subdir = getSubdir();
$path = "{$subdir}/{$type}/{$name}";
return $path;
});
return $latte;
}
@ -146,5 +155,4 @@ Route::add("/settings", function () use ($proxy_elements) {
header('Location: ./home');
}, 'POST');
$subdir = getenv('APP_SUBDIR');
Route::run($subdir);