Skip to content

Commit f1c7b89

Browse files
Merge pull request #103 from PostHog/reverse-proxy-fix
fix: route /array/* to assets origin
2 parents cb909f6 + f1f19a8 commit f1c7b89

8 files changed

Lines changed: 56 additions & 3 deletions

File tree

basics/next-app-router/next.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const nextConfig: NextConfig = {
88
source: "/ingest/static/:path*",
99
destination: "https://us-assets.i.posthog.com/static/:path*",
1010
},
11+
{
12+
source: "/ingest/array/:path*",
13+
destination: "https://us-assets.i.posthog.com/array/:path*",
14+
},
1115
{
1216
source: "/ingest/:path*",
1317
destination: "https://us.i.posthog.com/:path*",

basics/next-pages-router/next.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ const nextConfig: NextConfig = {
99
source: "/ingest/static/:path*",
1010
destination: "https://us-assets.i.posthog.com/static/:path*",
1111
},
12+
{
13+
source: "/ingest/array/:path*",
14+
destination: "https://us-assets.i.posthog.com/array/:path*",
15+
},
1216
{
1317
source: "/ingest/:path*",
1418
destination: "https://us.i.posthog.com/:path*",

basics/react-react-router-7-framework/vite.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ export default defineConfig(({ mode }) => {
1313
},
1414
server: {
1515
proxy: {
16+
'/ingest/static': {
17+
target: 'https://us-assets.i.posthog.com',
18+
changeOrigin: true,
19+
rewrite: (path) => path.replace(/^\/ingest/, ''),
20+
},
21+
'/ingest/array': {
22+
target: 'https://us-assets.i.posthog.com',
23+
changeOrigin: true,
24+
rewrite: (path) => path.replace(/^\/ingest/, ''),
25+
},
1626
'/ingest': {
1727
target: env.VITE_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com',
1828
changeOrigin: true,

basics/react-tanstack-router-code-based/vite.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ export default defineConfig(({ mode }) => {
1717
},
1818
server: {
1919
proxy: {
20+
'/ingest/static': {
21+
target: 'https://us-assets.i.posthog.com',
22+
changeOrigin: true,
23+
rewrite: (path) => path.replace(/^\/ingest/, ''),
24+
},
25+
'/ingest/array': {
26+
target: 'https://us-assets.i.posthog.com',
27+
changeOrigin: true,
28+
rewrite: (path) => path.replace(/^\/ingest/, ''),
29+
},
2030
'/ingest': {
2131
target: env.VITE_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com',
2232
changeOrigin: true,

basics/react-tanstack-router-file-based/vite.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ export default defineConfig(({ mode }) => {
2525
},
2626
server: {
2727
proxy: {
28+
'/ingest/static': {
29+
target: 'https://us-assets.i.posthog.com',
30+
changeOrigin: true,
31+
rewrite: (path) => path.replace(/^\/ingest/, ''),
32+
},
33+
'/ingest/array': {
34+
target: 'https://us-assets.i.posthog.com',
35+
changeOrigin: true,
36+
rewrite: (path) => path.replace(/^\/ingest/, ''),
37+
},
2838
'/ingest': {
2939
target: env.VITE_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com',
3040
changeOrigin: true,

basics/sveltekit/src/hooks.server.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ export const handle: Handle = async ({ event, resolve }) => {
77

88
// Reverse proxy for PostHog - route /ingest requests to PostHog servers
99
if (pathname.startsWith('/ingest')) {
10-
const hostname = pathname.startsWith('/ingest/static/')
11-
? 'us-assets.i.posthog.com'
12-
: 'us.i.posthog.com';
10+
const useAssetHost = pathname.startsWith('/ingest/static/') || pathname.startsWith('/ingest/array/')
11+
const hostname = useAssetHost ? 'us-assets.i.posthog.com' : 'us.i.posthog.com';
1312

1413
const url = new URL(event.request.url);
1514
url.protocol = 'https:';

basics/tanstack-start/vite.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ const config = defineConfig({
1414
],
1515
server: {
1616
proxy: {
17+
'/ingest/static': {
18+
target: 'https://us-assets.i.posthog.com',
19+
changeOrigin: true,
20+
rewrite: (path) => path.replace(/^\/ingest/, ''),
21+
secure: false,
22+
},
23+
'/ingest/array': {
24+
target: 'https://us-assets.i.posthog.com',
25+
changeOrigin: true,
26+
rewrite: (path) => path.replace(/^\/ingest/, ''),
27+
secure: false,
28+
},
1729
'/ingest': {
1830
target: 'https://us.i.posthog.com',
1931
changeOrigin: true,

transformation-config/commandments.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# Skills collect all commandments matching their tags
44

55
commandments:
6+
javascript:
7+
- 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).
8+
69
react:
710
# PostHog-specific
811
- For feature flags, use useFeatureFlagEnabled() or useFeatureFlagPayload() hooks - they handle loading states and external sync automatically
@@ -33,6 +36,7 @@ commandments:
3336
- Client-side hooks may return undefined initially while flags load - handle this loading state
3437

3538
javascript_web:
39+
- 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).
3640
- Remember that source code is available in the node_modules directory
3741
- Check package.json for type checking or build scripts to validate changes
3842
- posthog-js is the JavaScript SDK package name

0 commit comments

Comments
 (0)