aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
blob: f17214cbabaedb1610fe81515791046d6a9b9077 (plain)
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
33
34
35
36
37
38
39
//! This is the main executable file.
//! Here we will add all cli interfaces
//! to interact with the state of the application
//! but also the actual running of the server / webapp.

const std = @import("std");
const http = @import("http");
const html = @import("html");
const z = @import("z");

const badge = @import("web/badge/root.zig");

const document: html.Element = .native(.html, .{}, .children(&.{
    .native(.head, .{}, .children(&.{
        .native(.title, .{}, .content("Memora")),
        .native(.meta, .{
            .name = "viewport",
            .content = "width=device-width, initial-scale=1.0",
        }, .void),
        z.env(&.{
            badge.component,
        }),
    })),
    .native(.body, .{}, .children(&.{
        z.html.load(@embedFile("web/index.html")),
        z.component(.badge, .{}, .children(&.{
            .native(.span, .{ .slot = "content" }, .content("Hello Z (direct)!")),
        })),
    })),
}));

pub fn main(init: std.process.Init) !void {
    var server: http.Server = try .init(init.gpa, try .parseLiteral("127.0.0.1:8080"));
    try server.serve(comptime document.toDocument());
}

test {
    _ = std.testing.refAllDecls(@This());
}