Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions basics/next-app-router/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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*",
Expand Down
4 changes: 4 additions & 0 deletions basics/next-pages-router/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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*",
Expand Down
10 changes: 10 additions & 0 deletions basics/react-react-router-7-framework/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions basics/react-tanstack-router-code-based/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions basics/react-tanstack-router-file-based/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions basics/sveltekit/src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:';
Expand Down
12 changes: 12 additions & 0 deletions basics/tanstack-start/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions transformation-config/commandments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading