Wrangler configuration for monorepo

Hi! I have a monorepo with the following structure:
root/:
apps/:
app/: # static web app (1)
dist/: # build output
...
dash/: # static web app (2)
dist/: # build output
...
landing/: # static web app (3)
dist/: # build output
...
api/: # rest api in typescript
dist/: # build output (.js)
...
package.json
turbo.json
...
root/:
apps/:
app/: # static web app (1)
dist/: # build output
...
dash/: # static web app (2)
dist/: # build output
...
landing/: # static web app (3)
dist/: # build output
...
api/: # rest api in typescript
dist/: # build output (.js)
...
package.json
turbo.json
...
The static web apps won't run any other code on workers except for hosting the static content. The apps/api package however is an api that should run on an actual worker. apps/api needs a D1 database. The web apps should be accessible on different subdomains (I own the domain and it's using Cloudflare's DNS) How should I set wrangler up? Should I have four different wrangler.jsonc files, or should I have a root config that somehow incorporates these? Thanks!
2 Replies
yolocat
yolocatOP6mo ago
Wait, would I need a worker to simply serve the static assets for my web apps? answer: a wrangler config for each app, and I don’t need a worker for serving static assets
Gravite2090
Gravite20906mo ago
For my CF monorepo I have separate wrangler.jsonc files for every worker. I use pnpm to manage -- personal preference over turbo since I don't need what turbo solves for and don't want to pay for the complexity. So each worker has its own: package.json, wrangler.jsonc, tsconfig.json, readme, etc. I put shared packages of shared code, for example a D1 client or external api client, utils, etc -- in a "shared" directory in the root and each of those has their own package.json as well. Finally I have a databases directory where each D1 I make has migrations and schema to keep me sane. All that the deploys do in this case is migrate, no wrangler.jsonc involved. The reasons I prefer this setup are: - every worker really does need its own config file - that's just how Cloudflare designed Wrangler - different workers have different bindings, log requirements, compatibility flags, etc - my frontend workers that serve static assets use vite to build instead of wrangler and require unique configuration + cicd - this makes it easy to handle routes and multiple environments It's a lot of setup but once it is done and you get local running with debugging across a lot of workers it feels real nice. ---- regarding your question about a worker to serve static assets - your frontend workers should be doing that. So each of your frontend apps will have their own routes and assets configs in your wrangler configs.

Did you find this page helpful?