You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/workers/frameworks/framework-guides/hono.mdx
+61-33Lines changed: 61 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,59 +11,87 @@ import {
11
11
InlineBadge,
12
12
Render,
13
13
PackageManagers,
14
+
Steps,
15
+
Details,
16
+
FileTree,
14
17
} from"~/components";
15
18
16
-
In this guide, you will create a new [Hono](https://hono.dev/) application and deploy to Cloudflare Workers (with the new [<InlineBadgepreset="beta" /> Workers Assets](/workers/static-assets/)).
17
-
18
-
## 1. Set up a new project
19
-
20
-
Use the [`create-cloudflare`](https://www.npmjs.com/package/create-cloudflare) CLI (C3) to set up a new project. C3 will create a new project directory, use code from the official Hono template, and provide the option to deploy instantly.
21
-
22
-
To use `create-cloudflare` to create a new Hono project with <InlineBadgepreset="beta" /> Workers Assets, run the following command:
19
+
**Start from CLI** - scaffold a full-stack app with a Hono API, React SPA and the Cloudflare Vite plugin for lightning-fast development.
**Or just deploy** - create a full-stack app using Hono, React and Vite, with CI/CD and previews all set up for you.
38
29
39
-
After setting up your project, change your directory by running the following command:
30
+
[](https://dash.cloudflare.com/?to=/:account/workers-and-pages/create/deploy-to-workers&repository=https://github.com/cloudflare/templates/tree/staging/vite-react-template)
40
31
41
-
```sh
42
-
cd my-hono-app
43
-
```
32
+
## What is Hono?
44
33
45
-
## 2. Develop locally
34
+
[Hono](https://hono.dev/) is an ultra-fast, lightweight framework for building web applications, and works fantastically with Cloudflare Workers.
35
+
With Workers Assets, you can easily combine a Hono API running on Workers with a SPA to create a full-stack app.
46
36
47
-
After you have created your project, run the following command in the project directory to start a local server. This will allow you to preview your project locally during development.
37
+
## Creating a full-stack Hono app with a React SPA
48
38
49
-
<PackageManagerstype="run"args={"dev"} />
39
+
<Steps>
40
+
1.**Create a new project with the create-cloudflare CLI (C3)**
Your project can be deployed to a `*.workers.dev` subdomain or a [Custom Domain](/workers/configuration/routing/custom-domains/), from your own machine or from any CI/CD system, including [Cloudflare's own](/workers/ci-cd/builds/).
60
+
`wrangler.jsonc` is your [Wrangler configuration file](/workers/wrangler/configuration/).
61
+
In this file:
62
+
- `main` points to `src/worker/index.ts`. This is your Hono app, which will run in a Worker.
63
+
- `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.
64
+
- If you want to add bindings to resources on Cloudflare's developer platform, you configure them here. Read more about [bindings](/workers/runtime-apis/bindings/).
54
65
55
-
The following command will build and deploy your project. If you are using CI, ensure you update your ["deploy command"](/workers/ci-cd/builds/configuration/#build-settings) configuration appropriately.
66
+
`vite.config.ts` is set up to use the Cloudflare Vite plugin. This runs your Worker in Cloudflare's `workerd` runtime, ensuring your local development environment is as close to production as possible.
56
67
57
-
<PackageManagerstype="run"args={"deploy"} />
68
+
`src/worker/index.ts` is your Hono app, which contains a single endpoint to begin with, `/api`.
69
+
At `src/react-app/src/App.tsx`, your React app calls this endpoint to get a message back and displays this in your SPA.
70
+
</Details>
58
71
59
-
---
72
+
2.**Develop locally with the Cloudflare Vite plugin**
60
73
61
-
## Bindings
74
+
After creating your project, run the following command in your project directory to start a local development server.
75
+
<PackageManagerstype="run"args="dev" />
76
+
<Detailsheader="What's happening in local development?">
77
+
This project uses Vite for local development and build, and thus comes with all of Vite's features like hot module replacement (HMR).
78
+
In addition, `vite.config.ts` is set up to use the Cloudflare Vite plugin. This runs your application in Cloudflare's `workerd` runtime, just like in production, as well as access to local emulators of bindings.
79
+
</Details>
62
80
63
-
Your Hono application can be fully integrated with the Cloudflare Developer Platform, in both local development and in production, by using product bindings. The [Hono documentation](https://hono.dev/docs/getting-started/cloudflare-workers#bindings) provides information about configuring bindings and how you can access them.
81
+
3.**Deploy your project**
64
82
65
-
## Static assets
83
+
Your project can be deployed to a `*.workers.dev` subdomain or a [Custom Domain](/workers/configuration/routing/custom-domains/), from your own machine or from any CI/CD system, including Cloudflare's own [Workers Builds](/workers/ci-cd/builds/).
84
+
85
+
The following command will build and deploy your project. If you are using CI, ensure you update your ["deploy command"](/workers/ci-cd/builds/configuration/#build-settings) configuration appropriately.
86
+
87
+
<PackageManagerstype="run"args={"deploy"} />
88
+
89
+
</Steps>
90
+
91
+
---
92
+
93
+
## Bindings
66
94
67
-
You can serve static assets in your Hono application by [placing them in the `./public/` directory](https://hono.dev/docs/getting-started/cloudflare-workers#serve-static-files). This can be useful for resource files such as images, stylesheets, fonts, and manifests.
95
+
With bindings, your Hono application can be fully integrated with the Cloudflare Developer Platform, giving you access to storage, AI, image optimization and more. Refer to the [bindings overview](/workers/runtime-apis/bindings/)for more information on what's available and how to configure them.
68
96
69
-
<Renderfile="workers-assets-routing-summary" />
97
+
The [Hono documentation](https://hono.dev/docs/getting-started/cloudflare-workers#bindings) provides information on how you can access them in your Hono app.
0 commit comments