refactor: migrate web app to Workers + Static Assets format

The Cloudflare project was created as a Workers Build (the new
unified format), so the legacy Pages config (pages_build_output_dir,
functions/api/[[path]].ts) does not deploy. Switch to the modern
shape: a worker entry point that delegates to the Hono app for
/api/* and falls through to the [assets] binding for everything
else, with SPA fallback for client-side routes.

Build output (apps/web/dist) and bindings (D1, R2, env vars) are
unchanged.

https://claude.ai/code/session_01TPBqgcSJMppgrpiq7fLywL
This commit is contained in:
Claude 2026-05-04 00:57:28 +00:00
parent 36a7f57e17
commit 11167e48f3
No known key found for this signature in database
4 changed files with 29 additions and 12 deletions

View File

@ -1,7 +0,0 @@
import { createApp } from '@leetete/api';
import type { AppEnv } from '@leetete/api/env';
const app = createApp();
export const onRequest: PagesFunction<AppEnv> = (ctx) =>
app.fetch(ctx.request, ctx.env, ctx as unknown as ExecutionContext);

View File

@ -8,8 +8,8 @@
"build": "tsc --noEmit && vite build",
"preview": "vite preview",
"typecheck": "tsc --noEmit",
"deploy": "wrangler pages deploy dist --project-name stefanieeleandro",
"pages:dev": "wrangler pages dev dist --compatibility-flags=nodejs_compat"
"deploy": "wrangler deploy",
"pages:dev": "wrangler dev"
},
"dependencies": {
"@leetete/api": "workspace:*",

18
apps/web/src/worker.ts Normal file
View File

@ -0,0 +1,18 @@
import { createApp } from '@leetete/api';
import type { AppEnv } from '@leetete/api/env';
const app = createApp();
export interface Env extends AppEnv {
ASSETS: Fetcher;
}
export default {
async fetch(req, env, ctx) {
const url = new URL(req.url);
if (url.pathname.startsWith('/api/')) {
return app.fetch(req, env, ctx);
}
return env.ASSETS.fetch(req);
},
} satisfies ExportedHandler<Env>;

View File

@ -1,7 +1,13 @@
name = "stefanieeleandro"
main = "src/worker.ts"
compatibility_date = "2026-04-01"
compatibility_flags = ["nodejs_compat"]
pages_build_output_dir = "dist"
[assets]
directory = "./dist"
binding = "ASSETS"
not_found_handling = "single-page-application"
run_worker_first = ["/api/*"]
[[d1_databases]]
binding = "DB"
@ -20,9 +26,9 @@ S3_REGION = "auto"
S3_BUCKET = "wedding-media"
S3_FORCE_PATH_STYLE = "false"
# S3_ENDPOINT, S3_PUBLIC_BASE_URL, CF_ACCESS_TEAM, CF_ACCESS_AUD are
# set after Cloudflare config (see README of deploy steps).
# set after Cloudflare config (see deploy notes).
#
# Secrets (set via `wrangler pages secret put <NAME> --project-name stefanieeleandro`):
# Secrets (set via `wrangler secret put <NAME>` or via the dashboard):
# S3_ACCESS_KEY_ID
# S3_SECRET_ACCESS_KEY
# TURNSTILE_SECRET