Put mount base url in context

This commit is contained in:
jaina heartles 2022-12-14 00:20:25 -08:00
parent 8edf661afe
commit 0f5751e7ed

View file

@ -465,7 +465,16 @@ pub fn Mount(comptime route: []const u8) type {
var new_ctx = ctx;
new_ctx.path = args.path;
return next.handle(req, res, new_ctx, {});
if (@hasField(@TypeOf(new_ctx), "mounted_at")) {
new_ctx.mounted_at = try std.fmt.allocPrint(ctx.allocator, "/{s}/{s}", .{
std.mem.trim(u8, ctx.mounted_at, "/"),
std.mem.trim(u8, route, "/"),
});
defer ctx.allocator.free(new_ctx.mounted_at);
return next.handle(req, res, new_ctx, {});
} else {
return next.handle(req, res, addField(new_ctx, "mounted_at", std.mem.trim(u8, route, "/")), {});
}
}
};
}