Skip to content

Commit 864e863

Browse files
feat(web): migrate from pages to workers and add posthog analytics
1 parent bd13679 commit 864e863

File tree

8 files changed

+2096
-228
lines changed

8 files changed

+2096
-228
lines changed

apps/web/.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,20 @@
1212
/out/
1313
/build
1414
*.tsbuildinfo
15+
.open-next
1516

1617
# misc
1718
.DS_Store
1819
*.pem
1920
/.pnp
2021
.pnp.js
2122
npm-debug.log*
22-
yarn-debug.log*
23+
yarn-debug.log*
2324
yarn-error.log*
2425

2526
# others
2627
.env*.local
2728
.vercel
2829
next-env.d.ts
2930

30-
analytics-data.json
31+
analytics-data.json

apps/web/instrumentation-client.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import posthog from "posthog-js"
2+
3+
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
4+
api_host: "/ingest",
5+
ui_host: "https://us.posthog.com",
6+
defaults: '2025-05-24',
7+
capture_exceptions: true, // This enables capturing exceptions using Error Tracking
8+
debug: process.env.NODE_ENV === "development",
9+
});

apps/web/next.config.mjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,27 @@ const withMDX = createMDX();
55
/** @type {import('next').NextConfig} */
66
const config = {
77
reactStrictMode: true,
8-
output: "export",
8+
// This is required to support PostHog trailing slash API requests
9+
skipTrailingSlashRedirect: true,
910
experimental: {
1011
reactCompiler: true,
1112
},
13+
async rewrites() {
14+
return [
15+
{
16+
source: "/ingest/static/:path*",
17+
destination: "https://us-assets.i.posthog.com/static/:path*",
18+
},
19+
{
20+
source: "/ingest/:path*",
21+
destination: "https://us.i.posthog.com/:path*",
22+
},
23+
{
24+
source: "/ingest/decide",
25+
destination: "https://us.i.posthog.com/decide",
26+
},
27+
];
28+
},
1229
};
1330

1431
export default withMDX(config);

apps/web/open-next.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { defineCloudflareConfig } from "@opennextjs/cloudflare";
2+
3+
export default defineCloudflareConfig();

apps/web/package.json

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,49 @@
99
"start": "next start",
1010
"check": "biome check --write .",
1111
"postinstall": "fumadocs-mdx",
12+
"preview": "opennextjs-cloudflare build && opennextjs-cloudflare preview",
13+
"deploy": "opennextjs-cloudflare build && opennextjs-cloudflare deploy",
14+
"cf-typegen": "wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts",
1215
"generate-analytics": "bun scripts/generate-analytics.ts",
1316
"generate-schema": "bun scripts/generate-schema.ts"
1417
},
1518
"dependencies": {
19+
"@opennextjs/cloudflare": "^1.5.1",
1620
"babel-plugin-react-compiler": "^19.1.0-rc.2",
1721
"class-variance-authority": "^0.7.1",
1822
"clsx": "^2.1.1",
1923
"date-fns": "^4.1.0",
20-
"fumadocs-core": "15.5.1",
21-
"fumadocs-mdx": "11.6.7",
22-
"fumadocs-ui": "15.5.1",
23-
"lucide-react": "^0.513.0",
24-
"motion": "^12.18.1",
25-
"next": "15.3.3",
24+
"fumadocs-core": "15.6.3",
25+
"fumadocs-mdx": "11.6.11",
26+
"fumadocs-ui": "15.6.3",
27+
"lucide-react": "^0.525.0",
28+
"motion": "^12.23.3",
29+
"next": "15.3.5",
2630
"next-themes": "^0.4.6",
2731
"nuqs": "^2.4.3",
2832
"papaparse": "^5.5.3",
33+
"posthog-js": "^1.257.0",
2934
"radix-ui": "^1.4.2",
3035
"react": "^19.1.0",
3136
"react-dom": "^19.1.0",
3237
"react-tweet": "^3.2.2",
33-
"recharts": "^2.15.4",
34-
"sonner": "^2.0.5",
38+
"recharts": "^3.1.0",
39+
"sonner": "^2.0.6",
3540
"tailwind-merge": "^3.3.1"
3641
},
3742
"devDependencies": {
38-
"@tailwindcss/postcss": "^4.1.10",
43+
"@tailwindcss/postcss": "^4.1.11",
3944
"@types/mdx": "^2.0.13",
40-
"@types/node": "24.0.0",
45+
"@types/node": "24.0.13",
4146
"@types/papaparse": "^5.3.16",
4247
"@types/react": "^19.1.8",
4348
"@types/react-dom": "^19.1.6",
44-
"eslint": "^9.29.0",
45-
"eslint-config-next": "15.3.3",
49+
"eslint": "^9.31.0",
50+
"eslint-config-next": "15.3.5",
4651
"postcss": "^8.5.6",
47-
"tailwindcss": "^4.1.10",
48-
"tw-animate-css": "^1.3.4",
49-
"typescript": "^5.8.3"
52+
"tailwindcss": "^4.1.11",
53+
"tw-animate-css": "^1.3.5",
54+
"typescript": "^5.8.3",
55+
"wrangler": "^4.24.3"
5056
}
5157
}

apps/web/wrangler.jsonc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"main": ".open-next/worker.js",
3+
"name": "better-t-stack",
4+
"compatibility_date": "2025-07-13",
5+
"compatibility_flags": ["nodejs_compat"],
6+
"assets": {
7+
"directory": ".open-next/assets",
8+
"binding": "ASSETS"
9+
}
10+
}

bun.lock

Lines changed: 2031 additions & 208 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
"check": "turbo check",
1313
"format": "biome check --write .",
1414
"publish-packages": "turbo run build --filter=create-better-t-stack && changeset publish",
15-
"build:web:cloudflare": "bun install && bun run build:web",
16-
"deploy:web": "bun run build:web:cloudflare && bunx wrangler pages deploy ./apps/web/out"
15+
"deploy:web": "bun run --filter=web deploy"
1716
},
1817
"devDependencies": {
1918
"@biomejs/biome": "^2.0.2",

0 commit comments

Comments
 (0)