Adapters
Cloudflare
Run your h3 apps in Cloudflare Workers
You can directly host your h3 applications to Cloudflare Workers using Web Adapter.
Usage
Create app entry:
Create entry for a Cloudflare Worker:
Then, create a simple wrangler.toml
:
Finally, use wrangler dev
to locally preview:
npx wrangler dev
To deploy, use wrangler deploy
:
npx wrangler deploy
WebSocket support
import wsAdapter from "crossws/adapters/cloudflare";
const { handleUpgrade } = wsAdapter(app.websocket);
export default {
async fetch(request, env, ctx) {
if (request.headers.get("upgrade") === "websocket") {
return handleUpgrade(request, env, context);
}
return handler(request, {
cloudflare: { env, ctx },
});
},
};
👉 See pi0/h3-on-edge demo for a fully working example (deployment).