1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
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");
}
|