diff --git a/basics/next-app-router/next.config.ts b/basics/next-app-router/next.config.ts index 83b3a80..d3d1bf6 100644 --- a/basics/next-app-router/next.config.ts +++ b/basics/next-app-router/next.config.ts @@ -8,6 +8,10 @@ const nextConfig: NextConfig = { source: "/ingest/static/:path*", destination: "https://us-assets.i.posthog.com/static/:path*", }, + { + source: "/ingest/array/:path*", + destination: "https://us-assets.i.posthog.com/array/:path*", + }, { source: "/ingest/:path*", destination: "https://us.i.posthog.com/:path*", diff --git a/basics/next-pages-router/next.config.ts b/basics/next-pages-router/next.config.ts index 535e694..cc6405f 100644 --- a/basics/next-pages-router/next.config.ts +++ b/basics/next-pages-router/next.config.ts @@ -9,6 +9,10 @@ const nextConfig: NextConfig = { source: "/ingest/static/:path*", destination: "https://us-assets.i.posthog.com/static/:path*", }, + { + source: "/ingest/array/:path*", + destination: "https://us-assets.i.posthog.com/array/:path*", + }, { source: "/ingest/:path*", destination: "https://us.i.posthog.com/:path*", diff --git a/basics/react-react-router-7-framework/vite.config.ts b/basics/react-react-router-7-framework/vite.config.ts index 04681d4..32da564 100644 --- a/basics/react-react-router-7-framework/vite.config.ts +++ b/basics/react-react-router-7-framework/vite.config.ts @@ -13,6 +13,16 @@ export default defineConfig(({ mode }) => { }, server: { proxy: { + '/ingest/static': { + target: 'https://us-assets.i.posthog.com', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/ingest/, ''), + }, + '/ingest/array': { + target: 'https://us-assets.i.posthog.com', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/ingest/, ''), + }, '/ingest': { target: env.VITE_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com', changeOrigin: true, diff --git a/basics/react-tanstack-router-code-based/vite.config.ts b/basics/react-tanstack-router-code-based/vite.config.ts index 53cdc60..d34f1e2 100644 --- a/basics/react-tanstack-router-code-based/vite.config.ts +++ b/basics/react-tanstack-router-code-based/vite.config.ts @@ -17,6 +17,16 @@ export default defineConfig(({ mode }) => { }, server: { proxy: { + '/ingest/static': { + target: 'https://us-assets.i.posthog.com', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/ingest/, ''), + }, + '/ingest/array': { + target: 'https://us-assets.i.posthog.com', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/ingest/, ''), + }, '/ingest': { target: env.VITE_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com', changeOrigin: true, diff --git a/basics/react-tanstack-router-file-based/vite.config.ts b/basics/react-tanstack-router-file-based/vite.config.ts index dbc7c77..480602a 100644 --- a/basics/react-tanstack-router-file-based/vite.config.ts +++ b/basics/react-tanstack-router-file-based/vite.config.ts @@ -25,6 +25,16 @@ export default defineConfig(({ mode }) => { }, server: { proxy: { + '/ingest/static': { + target: 'https://us-assets.i.posthog.com', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/ingest/, ''), + }, + '/ingest/array': { + target: 'https://us-assets.i.posthog.com', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/ingest/, ''), + }, '/ingest': { target: env.VITE_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com', changeOrigin: true, diff --git a/basics/sveltekit/src/hooks.server.ts b/basics/sveltekit/src/hooks.server.ts index cadb1e2..8d25aac 100644 --- a/basics/sveltekit/src/hooks.server.ts +++ b/basics/sveltekit/src/hooks.server.ts @@ -7,9 +7,8 @@ export const handle: Handle = async ({ event, resolve }) => { // Reverse proxy for PostHog - route /ingest requests to PostHog servers if (pathname.startsWith('/ingest')) { - const hostname = pathname.startsWith('/ingest/static/') - ? 'us-assets.i.posthog.com' - : 'us.i.posthog.com'; + const useAssetHost = pathname.startsWith('/ingest/static/') || pathname.startsWith('/ingest/array/') + const hostname = useAssetHost ? 'us-assets.i.posthog.com' : 'us.i.posthog.com'; const url = new URL(event.request.url); url.protocol = 'https:'; diff --git a/basics/tanstack-start/vite.config.ts b/basics/tanstack-start/vite.config.ts index 4a7f2c4..6d25256 100644 --- a/basics/tanstack-start/vite.config.ts +++ b/basics/tanstack-start/vite.config.ts @@ -14,6 +14,18 @@ const config = defineConfig({ ], server: { proxy: { + '/ingest/static': { + target: 'https://us-assets.i.posthog.com', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/ingest/, ''), + secure: false, + }, + '/ingest/array': { + target: 'https://us-assets.i.posthog.com', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/ingest/, ''), + secure: false, + }, '/ingest': { target: 'https://us.i.posthog.com', changeOrigin: true, diff --git a/transformation-config/commandments.yaml b/transformation-config/commandments.yaml index c9de163..b291666 100644 --- a/transformation-config/commandments.yaml +++ b/transformation-config/commandments.yaml @@ -3,6 +3,9 @@ # Skills collect all commandments matching their tags commandments: + javascript: + - When a reverse proxy is configured, both /static/* AND /array/* must route to the assets origin (us-assets.i.posthog.com or eu-assets.i.posthog.com). + react: # PostHog-specific - For feature flags, use useFeatureFlagEnabled() or useFeatureFlagPayload() hooks - they handle loading states and external sync automatically @@ -33,6 +36,7 @@ commandments: - Client-side hooks may return undefined initially while flags load - handle this loading state javascript_web: + - When a reverse proxy is configured, both /static/* AND /array/* must route to the assets origin (us-assets.i.posthog.com or eu-assets.i.posthog.com). - Remember that source code is available in the node_modules directory - Check package.json for type checking or build scripts to validate changes - posthog-js is the JavaScript SDK package name