allow serving assets statically

This commit is contained in:
DrMaxNix 2024-02-10 18:47:44 +01:00
parent 2990988288
commit 7453d66ef8
2 changed files with 46 additions and 0 deletions

43
api/static/index.php Normal file
View File

@ -0,0 +1,43 @@
<?php
declare(strict_types = 1);
namespace Kimendisch\Sbgg_Jetzt;
use Flake\Project;
use Flake\Excuse;
// GET REQUESTED FILENAME //
// get from url parameter
$filename = Project::param("filename");
// resolve to storage path
$__file_path = ([
"logo-1024.png" => "./asset/logo-1024.png",
"logo-2048.png" => "./asset/logo-2048.png",
"logo-256.png" => "./asset/logo-256.png",
"logo-512.png" => "./asset/logo-512.png",
"logo-bg-1024.png" => "./asset/logo-bg-1024.png",
"logo-bg-2048.png" => "./asset/logo-bg-2048.png",
"logo-bg-256.png" => "./asset/logo-bg-256.png",
"logo-bg-512.png" => "./asset/logo-bg-512.png",
"logo.svg" => "./asset/logo.svg"
])[$filename] ?? null;
// validate lookup
if($__file_path === null){
Excuse::show("not_found");
}
// SERVE FILE //
// general headers
header("Access-Control-Allow-Origin: *");
// content length
header("Content-Length: " . filesize($__file_path));
// mimetype
$mime_content_type = mime_content_type($__file_path);
header("Content-type: " . $mime_content_type);
// file
readfile($__file_path);
?>

View File

@ -12,6 +12,7 @@
static::$ext[] = "file";
static::$ext[] = "hidden";
static::$ext[] = "project";
static::$ext[] = "excuse";
// ROUTES //
@ -29,5 +30,7 @@
["path" => ":lang", "target" => "page/start"],
["path" => "api/newsletter/subscribe", "target" => "api/newsletter/subscribe.php"]
["path" => "static/:filename", "target" => "api/static"],
];
?>