remove router for now
This commit is contained in:
parent
a9eb927570
commit
c774e56828
1 changed files with 10 additions and 7 deletions
17
src/main.zig
17
src/main.zig
|
@ -17,7 +17,7 @@ pub fn main() !void {
|
||||||
});
|
});
|
||||||
defer listener.deinit();
|
defer listener.deinit();
|
||||||
|
|
||||||
try listener.router.putRoute("/", &handle);
|
// try listener.router.putRoute("/", &handle);
|
||||||
// try listener.router.putRoute("/error", &handleError);
|
// try listener.router.putRoute("/error", &handleError);
|
||||||
// try listener.router.putRoute("//pee", &handleError);
|
// try listener.router.putRoute("//pee", &handleError);
|
||||||
// try listener.router.putRoute("/error/*", &handleError);
|
// try listener.router.putRoute("/error/*", &handleError);
|
||||||
|
@ -43,7 +43,8 @@ pub fn Listener(comptime Context: type) type {
|
||||||
/// Listen address
|
/// Listen address
|
||||||
address: net.Address,
|
address: net.Address,
|
||||||
/// Main router
|
/// Main router
|
||||||
router: Router,
|
// router: Router,
|
||||||
|
handler: HandlerFn,
|
||||||
|
|
||||||
/// Initialization options
|
/// Initialization options
|
||||||
pub const Options = struct {
|
pub const Options = struct {
|
||||||
|
@ -58,12 +59,13 @@ pub fn Listener(comptime Context: type) type {
|
||||||
return .{
|
return .{
|
||||||
.address = options.address,
|
.address = options.address,
|
||||||
.allocator = options.allocator,
|
.allocator = options.allocator,
|
||||||
.router = Router.init(options.allocator, options.root_handler),
|
.handler = options.root_handler,
|
||||||
|
// .router = Router.init(options.allocator, options.root_handler),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self) void {
|
pub fn deinit(_: *Self) void {
|
||||||
self.router.deinit();
|
// self.router.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Listens for new connections forever
|
/// Listens for new connections forever
|
||||||
|
@ -105,8 +107,9 @@ pub fn Listener(comptime Context: type) type {
|
||||||
var header_it = req.iterateHeaders();
|
var header_it = req.iterateHeaders();
|
||||||
while (header_it.next()) |header| try event.req.headers.append(&header);
|
while (header_it.next()) |header| try event.req.headers.append(&header);
|
||||||
|
|
||||||
const route = try self.router.getRoute(event.req.uri.path);
|
// const route = try self.router.getRoute(event.req.uri.path);
|
||||||
try route.handler(&event);
|
// try route.handler(&event);
|
||||||
|
try self.handler(&event);
|
||||||
|
|
||||||
try respondFromEvent(&event, &req, allocator);
|
try respondFromEvent(&event, &req, allocator);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue