Abhishek V GopalAll writing

2 May 2025

Deploying Next.js with a Hono backend on Cloudflare

Gigwork runs on Next.js (App Router) deployed to Cloudflare's Edge Runtime, with a Hono.js backend handling the API. The setup is fast and cheap to run, but the edge is not Node, and I learned that the hard way.

The edge is not Node

Code that works perfectly on your machine can fail once it's deployed to the edge. The Edge Runtime supports a smaller set of APIs than Node, and many libraries quietly assume a full Node or browser environment. You often don't find out until the code runs in production.

The bug that failed silently

The worst example was html2canvas, a browser-only library. On Cloudflare's Edge Runtime it crashed, which caused server errors on the affected pages. Next.js then silently injected noindex tags into them. The site looked fine to me, but Google was being told not to index those pages. Nothing in the UI hinted at it.

The lesson is to keep browser-only libraries out of anything that runs on the server or at the edge. Load them only in the browser, and only when the user actually needs them.

What I check before shipping now

After that experience I stopped trusting a page just because it renders. Now I look at the deployed page, not the local one. I view the page source and search for noindex or robots tags, check the status codes on key pages, and confirm the sitemap exists and includes every page that should rank, including the locality pages. I also validate the structured data schema, because errors there are easy to miss.

Caching needs the same attention. Incremental static regeneration and caching behave differently at the edge, so I check what is actually being served rather than assuming it matches what I just deployed.

Why a separate Hono backend

Keeping the API in a separate Hono.js backend keeps server logic away from the frontend's edge constraints. Hono is small, fast and easy to work with, which suits an API that has to talk to payments and WhatsApp integrations.

The takeaway

Edge deployment is worth it for the speed and cost, but it changes what can go wrong, and the failures are often silent. The habit that has paid off most is verifying what search engines and users actually receive, not what I think I shipped.