aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes/static.php
diff options
context:
space:
mode:
Diffstat (limited to 'routes/static.php')
-rw-r--r--routes/static.php19
1 files changed, 19 insertions, 0 deletions
diff --git a/routes/static.php b/routes/static.php
new file mode 100644
index 0000000..2850d8f
--- /dev/null
+++ b/routes/static.php
@@ -0,0 +1,19 @@
+<?php
+
+use Digitigrade\HttpResponseStatus\NotFound;
+use Digitigrade\Router;
+
+Router::getInstance()->mount('/static/:path', function (array $args) {
+ // TODO: support nested paths (needs changes in router i think)
+ $realPath = __DIR__ . '/../static/' . $args['path'];
+ if (!is_file($realPath)) {
+ throw new NotFound('static resource ' . $args['path'] . ' does not exist');
+ }
+ $fileExtension = explode('.', basename($realPath));
+ $fileExtension = $fileExtension[count($fileExtension) - 1];
+ header('Content-Type: ' . match ($fileExtension) {
+ 'css' => 'text/css',
+ default => mime_content_type($realPath)
+ });
+ echo file_get_contents($realPath);
+}); \ No newline at end of file