summaryrefslogtreecommitdiff
path: root/dev-server.php
diff options
context:
space:
mode:
authorJonas Kohl <gitlab@jonaskohl.de>2024-07-23 16:34:35 +0200
committerJonas Kohl <gitlab@jonaskohl.de>2024-07-23 16:34:35 +0200
commit252e4cfa9c2236e50f38adc4611396a5665f8301 (patch)
tree17a3359490f99ecbce2548d775a782fba6c40417 /dev-server.php
parente163c5950aa74278401679190fb7d755f730fa04 (diff)
Add codegen & emoticons
Diffstat (limited to 'dev-server.php')
-rw-r--r--dev-server.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/dev-server.php b/dev-server.php
index 2e5aacb..24969f6 100644
--- a/dev-server.php
+++ b/dev-server.php
@@ -8,6 +8,27 @@ const FALLBACK_FILE = TEMPLATE_DIR . "not_found.php";
const DEFAULT_FILE = TEMPLATE_DIR . "index.php";
const DEFAULT_MIME_TYPE = "application/octet-stream";
+$cg_map = [];
+$cg_dir = SRCDIR . "/codegen";
+
+foreach (scandir($cg_dir) as $cg_ent) {
+ $cg_path = $cg_dir . "/" . $cg_ent;
+ if (
+ $cg_ent[0] === "." ||
+ !is_file($cg_path) ||
+ strtolower(pathinfo($cg_ent, PATHINFO_EXTENSION)) !== "php"
+ ) continue;
+ $data = include $cg_path;
+ if (!is_array($data) || count($data) !== 2) {
+ trigger_error(
+ "Invalid data returned from codegen script '$cg_ent'",
+ E_USER_WARNING,
+ );
+ continue;
+ }
+ $cg_map[$data[0]] = $cg_path;
+}
+
function get_mime(string $filename): string {
static $mime_overrides = [
"css" => "text/css",
@@ -39,6 +60,17 @@ elseif (str_ends_with($name, ".html")) {
header("Content-Length: $len");
readfile($path);
exit;
+} elseif (isset($cg_map[$name])) {
+ $data = include $cg_map[$name];
+ if (!is_array($data) || count($data) !== 2) {
+ http_response_code(500);
+ echo "Invalid data returned from codegen script '$cg_ent'\n";
+ exit;
+ }
+ header("Content-Type: " . get_mime($data[0]));
+ header("Content-Length: " . strlen($data[1]));
+ echo $data[1];
+ exit;
}
$include_file = FALLBACK_FILE;