Hono - Cloudflare

Getting Started

Start from CLI – Scaffold a full-stack app with a Hono API, React SPA and the Cloudflare Vite plugin for lightning-fast development.

Terminal window
npm create cloudflare@latest -- hono-app --template=cloudflare/templates/vite-react-template

Or just deploy – create a full-stack app using Hono, React and Vite, with CI/CD and previews all set up for you.

Deploy to Cloudflare

How is this project set up?

Below is a simplified file tree of the project.

- src
- worker/
-index.ts
- react-app/
- index.html
- vite.config.ts
- wrangler.jsonc

wrangler.jsonc is your Wrangler configuration file. In this file:

  • main points to src/worker/index.ts. This is your Hono app, which will run in a Worker.
  • assets.not_found_handling is set to single-page-application, which means that routes that are handled by your SPA do not go to the Worker, and are thus free.
  • If you want to add bindings to resources on Cloudflare’s developer platform, you configure them here. Read more about bindings.

vite.config.ts is set up to use the Cloudflare Vite plugin. This runs your Worker in the Cloudflare Workers runtime, ensuring your local development environment is as close to production as possible.

src/worker/index.ts is your Hono app, which contains a single endpoint to begin with, /api. At src/react-app/src/App.tsx, your React app calls this endpoint to get a message back and displays this in your SPA.

Develop locally with the Cloudflare Vite plugin

After creating your project, run the following command in your project directory to start a local development server.

Terminal window
npm run dev

This project uses Vite for local development and build, and thus comes with all of Vite’s features, including hot module replacement (HMR).

In addition, vite.config.ts is set up to use the Cloudflare Vite plugin. This runs your application in the Cloudflare Workers runtime, just like in production, and enables access to local emulations of bindings.

Deploy your project

Your project can be deployed to a *.workers.dev subdomain or a Custom Domain, from your own machine or from any CI/CD system, including Cloudflare’s own Workers Builds.

The following command will build and deploy your project. If you are using CI, ensure you update your “deploy command” configuration appropriately.

Terminal window
npm run deploy

Bindings

The Hono documentation provides information on how you can access bindings in your Hono app.

With bindings, your application can be fully integrated with the Cloudflare Developer Platform, giving you access to compute, storage, AI and more.

Bindings

Pending