making room for context to add to the props

This commit is contained in:
Alan Daniels 2025-11-02 15:55:01 +11:00
parent 5aede0d096
commit ce67365a49
7 changed files with 44 additions and 26 deletions

View file

@ -15,13 +15,17 @@ pub fn init(connection: sqlite.Db) @This() {
};
}
pub fn SendInertiaResponse(endpoint: anytype, r: zap.Request, arena: Allocator, component: []const u8, props: anytype) !void {
pub fn SendInertiaResponse(endpoint: anytype, context: ?*@This(), r: zap.Request, arena: Allocator, component: []const u8, props: anytype) !void {
_ = context;
const inertia_json = try std.fmt.allocPrint(
arena,
"{f}",
.{std.json.fmt(.{
.component = component,
.props = props,
.props = .{
.nav = .{},
.page = props,
},
.url = endpoint.path,
.version = "",
}, .{
@ -82,6 +86,6 @@ pub const HtmlEncodeFormatter = struct {
};
pub fn unhandledRequest(ctx: *@This(), arena: Allocator, r: zap.Request) anyerror!void {
_ = ctx;
try SendInertiaResponse(.{ .path = r.path orelse "/" }, r, arena, "404", .{});
const path = r.path orelse "/not-found";
try SendInertiaResponse(.{ .path = path }, ctx, r, arena, "404", .{});
}