oscklm
oscklm•3d ago

How can i use built-in Convex HTTP router, with pull zone from a CDN?

Hey šŸ‘‹ Issue I'm attempting to set up a pull zone to retrieve data from an HTTP action endpoint using the standard Convex HTTP router, but encountering difficulties with dynamic endpoints. Details While I successfully implemented this using the Hono adapter from convex-helpers package (which supports dynamic endpoints like ⁠app.use("images/:storageId")), I'm struggling to achieve the same functionality with the built-in Convex HTTP router, which i for several reasons would much prefer using. Technical Context 1. The Hono adapter provides support for dynamic routes/slug routes (e.g., ⁠images/:storageId) which appears to be critical for my pull zone implementation, and how BunnyCDN handles the origin and the urls forwarded to that, when hitting the CDN. 2. I've also tried pointing the pull zone origin at a fixed files endpoint like ⁠https://******.convex.cloud/api/storage but encountered issues with the response format, maybe because it ain't returning a blob response like what i did with my hono implementation. Id love some advice from the team or anyone else, on whether it's possible to implement dynamic endpoints with the standard HTTP router (seems not) or if there are any other ways to achieve this. This is the hono implementation that worked (which id love to achieve with the built-in convex http router)
const app: HonoWithConvex<ActionCtx> = new Hono();

app.get("/images/:storageId", async (c) => {
const storageId = c.req.param("storageId") as Id<"_storage">;

const blob = await c.env.storage.get(storageId);
if (blob === null) {
return c.json({ error: "Image not found" }, 404);
}

return new Response(blob);
});

export default new HttpRouterWithHono(app);
const app: HonoWithConvex<ActionCtx> = new Hono();

app.get("/images/:storageId", async (c) => {
const storageId = c.req.param("storageId") as Id<"_storage">;

const blob = await c.env.storage.get(storageId);
if (blob === null) {
return c.json({ error: "Image not found" }, 404);
}

return new Response(blob);
});

export default new HttpRouterWithHono(app);
2 Replies
Convex Bot
Convex Bot•3d ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
aria
aria•2d ago
We are having the exact same issue, did you find a fix?

Did you find this page helpful?