From 556fa60fc94b8a8e63c2168352620de1c0970bfa Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Fri, 3 Nov 2023 15:41:45 +0800 Subject: [PATCH] Add an environment variable to conditionally use legacy rewrites These rewrites are not needed in dev, but in demo/production we should keep them for some older clients still. --- packages/web/next.config.js | 55 +++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/packages/web/next.config.js b/packages/web/next.config.js index 21ed643fa..f306d08ef 100644 --- a/packages/web/next.config.js +++ b/packages/web/next.config.js @@ -24,33 +24,34 @@ const moduleExports = { 'proxy.omnivore-image-cache.app', ], }, - rewrites: () => - (process.env.INCLUDE_LEGACY_REWRITES - ? [ - { - source: '/api/graphql', - destination: `https://api-${process.env.NEXT_PUBLIC_APP_ENV}.omnivore.app/api/graphql`, - }, - { - source: '/api/auth/:path*', - destination: `https://api-${process.env.NEXT_PUBLIC_APP_ENV}.omnivore.app/api/auth/:path*`, - }, - { - source: '/api/article/save', - destination: `https://api-${process.env.NEXT_PUBLIC_APP_ENV}.omnivore.app/api/article/save`, - }, - { - source: '/api/mobile-auth/:path*', - destination: `https://api-${process.env.NEXT_PUBLIC_APP_ENV}.omnivore.app/api/mobile-auth/:path*`, - }, - ] - : []) + - [ - { - source: '/collect/:match*', - destination: 'https://app.posthog.com/:match*', - }, - ], + rewrites: () => { + const rewrites = [] + if (process.env.INCLUDE_LEGACY_REWRITES) { + rewrites.push( + { + source: '/api/graphql', + destination: `https://api-${process.env.NEXT_PUBLIC_APP_ENV}.omnivore.app/api/graphql`, + }, + { + source: '/api/auth/:path*', + destination: `https://api-${process.env.NEXT_PUBLIC_APP_ENV}.omnivore.app/api/auth/:path*`, + }, + { + source: '/api/article/save', + destination: `https://api-${process.env.NEXT_PUBLIC_APP_ENV}.omnivore.app/api/article/save`, + }, + { + source: '/api/mobile-auth/:path*', + destination: `https://api-${process.env.NEXT_PUBLIC_APP_ENV}.omnivore.app/api/mobile-auth/:path*`, + } + ) + } + rewrites.push({ + source: '/collect/:match*', + destination: 'https://app.posthog.com/:match*', + }) + return rewrites + }, async headers() { return [ {