Skip to content

Commit f5c9bff

Browse files
authored
jandes-79: Deploy demo app to cloudflare workers
1 parent b37e82b commit f5c9bff

25 files changed

+774
-149
lines changed

.changeset/eleven-items-lick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"happy-harmony": minor
3+
---
4+
5+
JANDES-79: Deploy demo app to cloudflare workers

.dev.vars.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
AUTH_SECRET=
2+
AWS_REGION=
3+
AWS_ACCESS_KEY_ID=
4+
AWS_SECRET_ACCESS_KEY=
5+
SES_FROM_EMAIL=
6+
SENTRY_DSN=

.env.example

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
# Your Sentry DSN (from your Sentry account)
2-
VITE_SENTRY_DSN=""
3-
4-
# Your Sentry organization (from your Sentry account)
5-
VITE_SENTRY_ORG=""
6-
7-
# Your Sentry project (from your Sentry account)
8-
VITE_SENTRY_PROJECT=""
9-
10-
# Your Sentry authentication token (from your Sentry account)
11-
SENTRY_AUTH_TOKEN=""
1+
CI=
2+
VITE_SENTRY_ORG=
3+
VITE_SENTRY_PROJECT=
4+
SENTRY_AUTH_TOKEN=

.github/pull_request_template.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
- What changed and why?
44

5+
### Ticket
6+
7+
JANDES-###: <ticket name here>
8+
59
## Risks
610

711
- Where could this break or regress?

.github/workflows/playwright.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ jobs:
2727
cache-dependency-path: pnpm-lock.yaml
2828
- name: Install dependencies
2929
run: pnpm install --frozen-lockfile
30+
- name: Cache Playwright browsers
31+
uses: actions/cache@v4
32+
with:
33+
path: ~/.cache/ms-playwright
34+
key: ${{ runner.os }}-playwright-${{ hashFiles('pnpm-lock.yaml') }}
35+
restore-keys: |
36+
${{ runner.os }}-playwright-
3037
- name: Install Playwright Browsers
3138
run: pnpm exec playwright install --with-deps
3239
- name: Run Playwright tests

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ dist
44
dist-ssr
55
*.local
66
count.txt
7-
.env
7+
.env*
8+
!.env.example
89
.nitro
910
.tanstack
1011
.output
@@ -24,3 +25,7 @@ pnpm-workspace.yaml
2425
/blob-report/
2526
/playwright/.cache/
2627
/playwright/.auth/
28+
29+
# Wrangler
30+
.dev.vars
31+
!.dev.vars.example

docs/env.md

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,49 @@
1-
## Environment validation
1+
# Environment configuration
22

3-
- Server env is validated with Zod in `src/config/validation.ts` and parsed in `src/env.ts` during startup. Invalid or missing values throw immediately.
4-
- When `CI=true`, required keys: `VITE_SENTRY_ORG`, `VITE_SENTRY_PROJECT`, `SENTRY_AUTH_TOKEN`.
5-
- When `CI` is false/omitted, Sentry env is optional and the build runs without the Sentry wrapper.
6-
- `CI` is coerced to boolean, defaults to `false`.
7-
- `vite.config.ts` conditionally wraps with Sentry only when all Sentry env vars are present.
3+
This project separates build-time variables (used by Vite and CI) from runtime variables (provided by Cloudflare Workers).
84

9-
### Adding a new env var
5+
## Build-time env
106

11-
1. Add the key to `serverEnvSchema` in `src/config/validation.ts` (mark it required/optional as needed and document any CI-only requirements).
12-
2. Access it via `env.MY_KEY` from `src/env.ts`.
13-
3. Restart the dev server/build; invalid values will surface as startup errors.
7+
- Purpose: tooling only (e.g., Sentry sourcemap upload in CI).
8+
- Source: `.env.local` (optional) or CI env.
9+
- Keys: `CI`, `VITE_SENTRY_ORG`, `VITE_SENTRY_PROJECT`, `SENTRY_AUTH_TOKEN`.
10+
- Validation: `parseBuildEnv` in `src/config/validation.ts` (used by `vite.config.ts`).
11+
12+
## Runtime env (Workers)
13+
14+
- Purpose: secrets and bindings used by server code at runtime.
15+
- Source: Cloudflare bindings; local via `.dev.vars` when running `wrangler dev`.
16+
- Keys: `AUTH_SECRET`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `SES_FROM_EMAIL`, optional `SENTRY_DSN`.
17+
- Access: `getRuntimeEnv()` from `src/config/runtimeEnv.ts` (Workers runtime only; not for client imports).
18+
- Validation: Zod schema in `runtimeEnv.ts`; errors list missing keys but never values.
19+
20+
## Local setup
21+
22+
- Build-time: optionally copy `.env.example` to `.env.local` and fill Sentry fields if you need CI-style sourcemap uploads locally.
23+
- Runtime: copy `.dev.vars.example` to `.dev.vars` and fill values; `wrangler dev` will load them.
24+
- Run: `pnpm dev` (uses `wrangler dev` on port 3000). `pnpm dev:vite` is available as a Vite-only fallback.
25+
26+
## Staging/production
27+
28+
- Secrets (`AUTH_SECRET`, AWS keys) should be set with `wrangler secret put`.
29+
- Non-secrets (`AWS_REGION`, `SES_FROM_EMAIL`, optional `SENTRY_DSN`) can be set via `vars` in `wrangler.toml` or `wrangler deploy --var KEY=value`.
30+
- Build-time Sentry vars for CI are configured in the CI environment (match `.env.example` keys).
31+
- Runtime env must be read only through `getRuntimeEnv()` inside server code.
32+
33+
## Validation
34+
35+
- Build-time keys are validated by `buildEnvSchema` in `src/config/validation.ts` and parsed via `parseBuildEnv` in `vite.config.ts` / `src/env.ts`. When `CI=true`, Sentry keys are required; otherwise they stay optional.
36+
- Runtime keys are validated by `getRuntimeEnv()` in `src/config/runtimeEnv.ts`; error messages list missing keys without revealing values.
37+
38+
## Sentry defaults
39+
40+
- Server (Workers): DSN from runtime `SENTRY_DSN` via `getRuntimeEnv()`. Sample rates: traces 0.1 / profiles 0.1 in production, 1.0 in dev/staging. Environment comes from `WORKERS_ENVIRONMENT`/`NODE_ENV`.
41+
- Client: DSN from `VITE_SENTRY_DSN` (optional). Sample rates mirror server; replays are off by default (`replaysSessionSampleRate=0`, `replaysOnErrorSampleRate=1.0`). Environment uses `import.meta.env.MODE`.
42+
43+
## Testing
44+
45+
- Playwright uses `pnpm dev` (wrangler) so e2e hits the Workers runtime on port 3000. `.dev.vars` must be present for runtime bindings.
46+
47+
## Deployment
48+
49+
- `workers_dev` is enabled for the first deploy to `*.workers.dev`. Route settings remain in `wrangler.jsonc` for attaching the custom domain afterward.

package.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
"private": true,
55
"type": "module",
66
"scripts": {
7-
"dev": "vite dev --port 3000",
7+
"dev": "wrangler dev --port 3000",
8+
"dev:vite": "vite dev --port 3000",
89
"start": "node .output/server/index.mjs",
910
"build": "vite build",
1011
"serve": "vite preview",
11-
"test": "vitest run",
12+
"test": "VITEST=true vitest run",
1213
"test:e2e": "pnpm exec playwright test",
1314
"test:e2e:report": "pnpm exec playwright show-report",
1415
"test:watch": "vitest",
1516
"test:cov": "vitest run --coverage",
1617
"prepare": "husky",
17-
"change": "pnpm exec changeset",
18+
"change": "pnpm exec changeset && git add .changeset",
1819
"change:empty": "pnpm exec changeset add --empty",
1920
"lint": "pnpm exec eslint --cache --cache-location .eslintcache .",
2021
"lint:fix": "pnpm exec eslint --cache --cache-location .eslintcache --fix .",
@@ -28,9 +29,14 @@
2829
"changeset:publish": "pnpm exec changeset publish",
2930
"check": "pnpm run typecheck && pnpm run lint && pnpm run test",
3031
"clean": "rm -rf .turbo node_modules .wrangler .output dist",
31-
"deploy": "wrangler deploy"
32+
"deploy": "pnpm run build && wrangler deploy",
33+
"deploy:staging": "pnpm run build && wrangler deploy --env staging",
34+
"deploy:production": "pnpm run build && wrangler deploy --env production",
35+
"preview": "pnpm run build && vite preview",
36+
"cf-typegen": "wrangler types"
3237
},
3338
"dependencies": {
39+
"@cloudflare/vite-plugin": "^1.20.1",
3440
"@emotion/react": "^11.14.0",
3541
"@emotion/styled": "^11.14.1",
3642
"@sentry/cloudflare": "^10.32.1",
@@ -89,7 +95,7 @@
8995
"vite": "^7.3.1",
9096
"vitest": "^3.0.5",
9197
"web-vitals": "^5.1.0",
92-
"wrangler": "^4.58.0"
98+
"wrangler": "^4.59.2"
9399
},
94100
"engines": {
95101
"node": ">=18.18"

playwright.config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineConfig, devices } from "@playwright/test";
22

3-
const PORT = 4173;
4-
const BASE_URL = `http://127.0.0.1:${PORT}`;
3+
const PORT = 3000;
4+
const BASE_URL = `http://localhost:${PORT}`;
55

66
/**
77
* Read environment variables from file.
@@ -15,7 +15,7 @@ const BASE_URL = `http://127.0.0.1:${PORT}`;
1515
* See https://playwright.dev/docs/test-configuration.
1616
*/
1717
export default defineConfig({
18-
testDir: "./e2eTests",
18+
testDir: "./e2e",
1919
/* Run tests in files in parallel */
2020
fullyParallel: true,
2121
/* Fail the build on CI if you accidentally left test.only in the source code. */
@@ -44,13 +44,13 @@ export default defineConfig({
4444
},
4545

4646
webServer: {
47-
command: `pnpm exec vite dev --host --port ${PORT}`,
47+
command: "pnpm dev:vite",
4848
url: BASE_URL,
4949
reuseExistingServer: !process.env.CI,
5050
stdout: "pipe",
5151
env: {
5252
...process.env,
53-
SKIP_ENV_LOAD: "true",
53+
PLAYWRIGHT_TEST: "true",
5454
},
5555
},
5656

0 commit comments

Comments
 (0)