2022-04-02 20:23:18 +00:00
|
|
|
const std = @import("std");
|
2022-06-09 05:54:41 +00:00
|
|
|
const util = @import("util");
|
2022-04-23 07:11:40 +00:00
|
|
|
|
|
|
|
pub const db = @import("./db.zig");
|
2022-04-23 07:25:45 +00:00
|
|
|
pub const http = @import("./http.zig");
|
2022-05-23 02:14:11 +00:00
|
|
|
pub const routing = @import("./routing.zig");
|
2022-04-02 20:23:18 +00:00
|
|
|
|
2022-04-23 07:25:45 +00:00
|
|
|
pub const Uuid = util.Uuid;
|
|
|
|
pub const ciutf8 = util.ciutf8;
|
2022-04-02 20:23:18 +00:00
|
|
|
|
2022-06-09 06:37:09 +00:00
|
|
|
fn testHandler(ctx: *const http.Context) !void {
|
|
|
|
const stream = try ctx.response.open(.ok);
|
|
|
|
defer stream.close();
|
2022-04-02 20:23:18 +00:00
|
|
|
|
2022-06-09 06:37:09 +00:00
|
|
|
try stream.writer().writeAll("Index page");
|
2022-04-04 03:36:32 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 20:23:18 +00:00
|
|
|
pub fn main() anyerror!void {
|
|
|
|
var srv = std.net.StreamServer.init(.{ .reuse_address = true });
|
|
|
|
defer srv.deinit();
|
|
|
|
|
2022-04-21 09:34:04 +00:00
|
|
|
const uuid = try Uuid.parse("f75f5160-12d3-42c2-a81d-ad2245b7a74b");
|
|
|
|
std.log.debug("{}", .{uuid});
|
|
|
|
|
2022-04-02 20:23:18 +00:00
|
|
|
try srv.listen(std.net.Address.parseIp("0.0.0.0", 8080) catch unreachable);
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
const conn = try srv.accept();
|
|
|
|
|
|
|
|
// todo: keep track of connections
|
2022-06-09 06:37:09 +00:00
|
|
|
_ = async http.handleConnection(std.heap.page_allocator, conn, struct {
|
|
|
|
fn func(ctx: *const http.Context) !void {
|
|
|
|
return testHandler(ctx);
|
2022-05-23 02:14:11 +00:00
|
|
|
}
|
|
|
|
}.func);
|
2022-04-02 20:23:18 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-20 04:46:39 +00:00
|
|
|
|
|
|
|
test {
|
|
|
|
_ = http;
|
2022-05-24 02:05:28 +00:00
|
|
|
_ = util;
|
|
|
|
_ = routing;
|
2022-05-20 04:46:39 +00:00
|
|
|
}
|