diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-05-20 10:16:50 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-05-20 10:16:50 +0200 |
| commit | 44445734ba4a0f05564f808c2fd34a7f23c6fafb (patch) | |
| tree | 3bd22add718620cbf931286f55137bcc666100be /src/routes/static.zig | |
| parent | 95ae9f15e1db335a7f8358d811ea37e2c89dd10f (diff) | |
Let's do a rewrite!
Created project structure and changed `build.zig` and added licence.
Diffstat (limited to 'src/routes/static.zig')
| -rw-r--r-- | src/routes/static.zig | 35 |
1 files changed, 0 insertions, 35 deletions
diff --git a/src/routes/static.zig b/src/routes/static.zig deleted file mode 100644 index f8f7a6c..0000000 --- a/src/routes/static.zig +++ /dev/null @@ -1,35 +0,0 @@ -const std = @import("std"); -const mime = @import("../mime.zig"); -const config = @import("config"); - -const memora = @import("memora"); -const Context = memora.Context; - -const log = std.log.scoped(.fallback); - -pub const access = .everyone; - -pub fn get(ctx: *Context) anyerror!memora.Stream { - var static = try std.fs.cwd().openDir(config.static_path, .{}); - defer static.close(); - - if (static.openFile(ctx.request.head.target[1..], .{})) |file| { - const mime_type = mime.get_type(ctx.request.head.target); - ctx.response.headers.content_type = mime_type; - return .from_file(file); - } else |_| { - var subdir = if (ctx.request.head.target.len == 1) static - else (static.openDir(ctx.request.head.target[1..], .{}) catch { - return error.NotFound; - }); - defer if (ctx.request.head.target.len > 1) subdir.close(); - - if (subdir.openFile("index.html", .{})) |file| { - ctx.response.headers.content_type = "text/html"; - return .from_file(file); - } else |_| { - log.warn("File '{s}' Not Found", .{ ctx.request.head.target }); - return error.NotFound; - } - } -} |