Last Updated: 3/11/2026
Cloudflare Pages
Cloudflare Pages is an edge platform for full-stack web applications, serving static files and dynamic content via Cloudflare Workers.
Setup
Create a new Cloudflare Pages project:
npm create hono@latest my-appSelect cloudflare-pages, then install dependencies:
cd my-app
npm installDirectory structure:
./
├── package.json
├── public
│ └── static
│ └── style.css
├── src
│ ├── index.tsx
│ └── renderer.tsx
├── tsconfig.json
└── vite.config.tsHello World
Edit src/index.tsx:
import { Hono } from 'hono'
import { renderer } from './renderer'
const app = new Hono()
app.get('*', renderer)
app.get('/', (c) => {
return c.render(<h1>Hello, Cloudflare Pages!</h1>)
})
export default appRun Locally
Start the Vite dev server:
npm run devAccess http://localhost:5173 in your browser.
Deploy
Deploy to Cloudflare:
npm run deployDeploy via GitHub
- Log in to Cloudflare dashboard
- Go to Workers & Pages > Create application > Pages > Connect to Git
- Configure:
- Production branch:
main - Build command:
npm run build - Build directory:
dist
- Production branch:
Bindings
Use Cloudflare Bindings (Variables, KV, D1):
Create wrangler.toml
[vars]
MY_NAME = "Hono"
[[kv_namespaces]]
binding = "MY_KV"
id = "your-kv-id"Use in Application
type Bindings = {
MY_NAME: string
MY_KV: KVNamespace
}
const app = new Hono<{ Bindings: Bindings }>()
app.get('/', async (c) => {
await c.env.MY_KV.put('name', c.env.MY_NAME)
const name = await c.env.MY_KV.get('name')
return c.render(<h1>Hello! {name}</h1>)
})Client-Side Scripts
Import client scripts using Vite:
app.get('/', (c) => {
return c.html(
<html>
<head>
{import.meta.env.PROD ? (
<script type='module' src='/static/client.js'></script>
) : (
<script type='module' src='/src/client.ts'></script>
)}
</head>
<body>
<h1>Hello</h1>
</body>
</html>
)
})Cloudflare Pages Middleware
Use Hono middleware as Cloudflare Pages middleware:
// functions/_middleware.ts
import { handleMiddleware } from 'hono/cloudflare-pages'
import { basicAuth } from 'hono/basic-auth'
export const onRequest = handleMiddleware(
basicAuth({
username: 'admin',
password: 'secret',
})
)Multiple middleware:
export const onRequest = [
handleMiddleware(middleware1),
handleMiddleware(middleware2),
]