-
UPDATE: With the stable v3 release, you can now use an adapter for this purpose. I'll keep Yusuke's answer marked as an answer for historical reasons but if you want to use Hono in Cloudflare Pages, please refer to the Adapter section of the release note. I'm trying to use Hono with Cloudflare Pages Functions, but it seems that Hono's context cannot access to CF bindings. Suppose I have the following Cloudflare Workers binding, // functions/workers-binding.d.ts
type Env = {
KV_FOR_REPRO: KVNamespace
} and two routings for Functions, which are // functions/api/raw.ts
export const onRequestGet: PagesFunction<Env> = async ({ env }) => {
await env.KV_FOR_REPRO.list();
return new Response("Without Hono!");
}; // functions/api/hono/[[route]].ts
import { Hono } from "hono";
const api = new Hono<{ Bindings: Env }>();
api.get("/", async (c) => {
await c.env.KV_FOR_REPRO.list();
return c.text("With Hono!");
});
const app = new Hono();
app.route("/api/hono", api);
export const onRequestGet: PagesFunction = ({ request }) => app.fetch(request); Then after starting a dev server by
If I remove I'm not sure if this is my mistake or a bug. Could anyone help me troubleshoot this? Reproduction repo is available at https://github.com/yudai-nkt/hono-with-pages-function-bindings UPDATE: With the following module Worker and a dev server served by // functions/worker.ts
import { Hono } from "hono";
const api = new Hono<{ Bindings: Env }>();
api.get("/", async (c) => {
await c.env.KV_FOR_REPRO.list();
return c.text("With Hono!");
});
const app = new Hono();
app.route("/api/hono", api);
export default app; |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Hi @yudai-nkt ! If you want to use Hono in Pages Functions, you can use "advanced mode". https://developers.cloudflare.com/pages/platform/functions/advanced-mode/ With |
Beta Was this translation helpful? Give feedback.
-
In v3.0.0-rc.8, you can use the |
Beta Was this translation helpful? Give feedback.
Hi @yudai-nkt !
If you want to use Hono in Pages Functions, you can use "advanced mode".
https://developers.cloudflare.com/pages/platform/functions/advanced-mode/
https://github.com/honojs/examples/tree/main/pages
With
onRequestGet
, it does not work well.