Skip to content

Commit 7b5a656

Browse files
Fix: Add ASSETS binding to wrangler configuration and update backendMain to handle static assets
1 parent 75b51a8 commit 7b5a656

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/backendMain.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { memberRouter } from './backend/routers/member'
66
import { handleCronJob } from './backend/services/cron'
77
import { CloudflareBindings } from './backend/models/types'
88

9-
const app = new Hono<{ Bindings: CloudflareBindings }>()
9+
type Bindings = CloudflareBindings & {
10+
ASSETS: any // Cloudflare Assets binding
11+
}
12+
13+
const app = new Hono<{ Bindings: Bindings }>()
1014

1115
// API Routes
1216
app.route('/api/auth', authRouter)
@@ -20,6 +24,12 @@ frontendRoutes.forEach(route => {
2024
app.get(route, renderer);
2125
});
2226

27+
// Handle static assets
28+
app.get('/client/*', async (c) => {
29+
const assetPath = c.req.path.replace('/client', '')
30+
return c.env.ASSETS.fetch(new Request(`${new URL(c.req.url).origin}${assetPath}`))
31+
})
32+
2333
// Catch-all route for client-side routing
2434
app.get('*', (c) => {
2535
const path = c.req.path

wrangler.jsonc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
"compatibility_date": "2025-08-03",
55
"compatibility_flags": ["nodejs_compat"],
66
"main": "./src/backendMain.tsx",
7+
"assets": {
8+
"directory": "./dist/client",
9+
"binding": "ASSETS"
10+
},
711
"d1_databases": [
812
{
913
"binding": "DB",

0 commit comments

Comments
 (0)