Skip to content

Commit d0d67c4

Browse files
committed
feat: local workerd dev setup and guide
1 parent 4646033 commit d0d67c4

5 files changed

Lines changed: 36 additions & 1 deletion

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ To develop all apps and packages, run the following command:
140140

141141
For local development environment variables / secrets, create a copy of `.env.dev` to `.env.dev.local`.
142142

143+
#### Wrangler / Cloudflare Workers
144+
145+
Guide to setup local development for Cloudflare `workerd` runtime testing:
146+
* (Optional) Run the convex dev server if you use convex.
147+
* Config `wrangler.jsonc`, specfically, the `vars` block, so that it properly targets the local env.
148+
* (Optional) Config [`apps/frontend/.env.workerd.dev`](apps/frontend/.env.workerd.dev) if you use convex or use different ip/port.
149+
* Build a new static dist for local dev:
150+
* Start the local `backend` server
151+
* Run `build:workerdLocal` script for `frontend`.
152+
* Run `pnpm dlx wrangler dev` to start wrangler dev server.
153+
* `workerd` does not work with Alpine Linux, so if you use the included Dev Container, change the base image to some other distro.
154+
143155
### Deploy
144156

145157
* You can add your custom deploy instructions in `deploy` script and `scripts/deploy.sh` in each app, it could be a full script that deploys to a platform, or necessary actions before for some platform integration deploys it, `frontend` will only start [build and deploy after all backends are deployed](./apps/frontend/turbo.json), to have context for SSG.

apps/frontend/.env.workerd.dev

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
NUXT_PUBLIC_FRONTEND_URL=https://127.0.0.1:3310
2+
NUXT_PUBLIC_BACKEND_URL=https://127.0.0.1:3310
3+
NUXT_PUBLIC_CONVEX_URL=

apps/frontend/nuxt.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import { config } from 'dotenv'
66
import { bundledLanguagesInfo } from 'shiki/bundle/full'
77
import optimizeExclude from 'vite-plugin-optimize-exclude'
88

9-
if (import.meta.env.NODE_ENV === 'development') {
9+
import.meta.env.TARGET ??= import.meta.env.NODE_ENV
10+
11+
if (import.meta.env.TARGET === 'workerdLocal') {
12+
config({ path: ['.env.workerd.dev.local', '.env.workerd.dev'] })
13+
import.meta.env.NUXT_PUBLIC_CONVEX_URL ||= (await getConvexEnvs()).CONVEX_URL || ''
14+
}
15+
else if (import.meta.env.TARGET === 'development') {
1016
config({ path: ['.env.dev.local', '.env.dev'] })
1117
import.meta.env.NUXT_PUBLIC_CONVEX_URL ||= (await getConvexEnvs()).CONVEX_URL || ''
1218
}

apps/frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"quickcheck": "pnpm run lint && pnpm run test:types",
1010
"dev": "nuxt dev",
1111
"build": "nuxt generate",
12+
"build:workerdLocal": "export TARGET=workerdLocal && nuxt generate",
1213
"deploy": "pnpm run build && sh scripts/deploy.sh",
1314
"preview": "nuxt preview",
1415
"postinstall": "nuxt prepare",

wrangler.jsonc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
"directory": "./apps/frontend/.output/public/"
1717
},
1818
"upload_source_maps": true,
19+
"dev": {
20+
"ip": "127.0.0.1",
21+
"port": 3310,
22+
"local_protocol": "https"
23+
},
1924

2025
/**
2126
* Smart Placement
@@ -46,6 +51,14 @@
4651
"KINDE_REDIRECT_URI": "https://starter-monorepo.isthe.top/api/auth/callback",
4752
"FRONTEND_URL": "https://starter-monorepo.isthe.top",
4853
"CONVEX_URL": "https://amiable-octopus-367.convex.cloud",
54+
55+
// The block below is intended for local development
56+
// "KINDE_DOMAIN": "https://topnames-dev.eu.kinde.com",
57+
// "KINDE_LOGOUT_REDIRECT_URI": "https://127.0.0.1:3310",
58+
// "KINDE_REDIRECT_URI": "https://127.0.0.1:3310/api/auth/callback",
59+
// "FRONTEND_URL": "https://127.0.0.1:3310",
60+
// "CONVEX_URL": "https://dazzling-panther-382.convex.cloud",
61+
4962
"NO_COLOR": "true"
5063
},
5164

0 commit comments

Comments
 (0)