const httpz = @import("httpz"); const std = @import("std"); const common = @import("common.zig"); pub fn index(_: *common.Env, _: *httpz.Request, res: *httpz.Response) !void { try static_file(res, "public/index.html", httpz.ContentType.HTML); } pub fn main_css(_: *common.Env, _: *httpz.Request, res: *httpz.Response) !void { try static_file(res, "public/main.css", httpz.ContentType.CSS); } pub fn main_js(_: *common.Env, _: *httpz.Request, res: *httpz.Response) !void { try static_file(res, "public/main.js", httpz.ContentType.JS); } pub fn icon_png(_: *common.Env, _: *httpz.Request, res: *httpz.Response) !void { try static_file(res, "public/icon.png", httpz.ContentType.PNG); } fn static_file(res: *httpz.Response, path: []const u8, content_type: httpz.ContentType) !void { const file = try std.fs.cwd().openFile(path, .{}); defer file.close(); const stat = try file.stat(); const buf: []u8 = try file.readToEndAlloc(res.arena, stat.size); res.body = buf; res.content_type = content_type; res.header("cache-control", "no-cache, no-store, must-revalidate"); }