diff --git a/apps/viewer/next.config.mjs b/apps/viewer/next.config.mjs index 310069125..70ad531bd 100644 --- a/apps/viewer/next.config.mjs +++ b/apps/viewer/next.config.mjs @@ -37,8 +37,23 @@ const landingPagePaths = [ '/about', '/oss-friends', '/blog', + '/blog/:slug*', ] +const landingPageReferers = [ + '/', + '/pricing', + '/privacy-policies', + '/terms-of-service', + '/about', + '/oss-friends', + '/blog', +].concat(['/blog/(.+)']) + +const currentHost = 'typebot.io' +const currentOrigin = `https://${currentHost}` +const optionalQueryParams = `(\\/?\\?.*)?` + /** @type {import('next').NextConfig} */ const nextConfig = { reactStrictMode: true, @@ -72,39 +87,39 @@ const nextConfig = { async rewrites() { return { beforeFiles: (process.env.LANDING_PAGE_URL - ? landingPagePaths + ? landingPageReferers .map((path) => ({ source: '/_next/static/:static*', has: [ { type: 'header', key: 'referer', - value: `https://typebot.io${path}`, + value: `${currentOrigin}${path}${optionalQueryParams}`, }, ], destination: `${process.env.LANDING_PAGE_URL}/_next/static/:static*`, })) .concat( - landingPagePaths.map((path) => ({ + landingPageReferers.map((path) => ({ source: '/typebots/:typebot*', has: [ { type: 'header', key: 'referer', - value: `https://typebot.io${path}`, + value: `${currentOrigin}${path}${optionalQueryParams}`, }, ], destination: `${process.env.LANDING_PAGE_URL}/typebots/:typebot*`, })) ) .concat( - landingPagePaths.map((path) => ({ + landingPageReferers.map((path) => ({ source: '/styles/:style*', has: [ { type: 'header', key: 'referer', - value: `https://typebot.io${path}`, + value: `${currentOrigin}${path}${optionalQueryParams}`, }, ], destination: `${process.env.LANDING_PAGE_URL}/styles/:style*`, @@ -116,79 +131,25 @@ const nextConfig = { has: [ { type: 'host', - value: 'typebot.io', + value: currentHost, }, ], destination: `${process.env.LANDING_PAGE_URL}${path}`, })) ) - .concat([ - { - source: '/blog/:slug', - has: [ - { - type: 'host', - value: 'typebot.io', - }, - ], - destination: `${process.env.LANDING_PAGE_URL}/blog/:slug`, - }, - { - source: '/_next/static/:static*', + .concat( + landingPageReferers.map((path) => ({ + source: '/images/:image*', has: [ { type: 'header', key: 'referer', - value: `https://typebot.io/blog/(?.*)`, + value: `${currentOrigin}${path}${optionalQueryParams}`, }, ], - destination: `${process.env.LANDING_PAGE_URL}/_next/static/:static*`, - }, - { - source: '/images/blog/:images*', - has: [ - { - type: 'header', - key: 'referer', - value: `https://typebot.io/blog/(?.*)`, - }, - ], - destination: `${process.env.LANDING_PAGE_URL}/images/blog/:images*`, - }, - { - source: '/images/blog/:images*', - has: [ - { - type: 'header', - key: 'referer', - value: `https://typebot.io/blog`, - }, - ], - destination: `${process.env.LANDING_PAGE_URL}/images/blog/:images*`, - }, - { - source: '/typebots/:typebot*', - has: [ - { - type: 'header', - key: 'referer', - value: `https://typebot.io/blog/(?.*)`, - }, - ], - destination: `${process.env.LANDING_PAGE_URL}/typebots/:typebot*`, - }, - { - source: '/styles/:style*', - has: [ - { - type: 'header', - key: 'referer', - value: `https://typebot.io/blog/(?.*)`, - }, - ], - destination: `${process.env.LANDING_PAGE_URL}/styles/:style*`, - }, - ]) + destination: `${process.env.LANDING_PAGE_URL}/images/:image*`, + })) + ) : [] ) .concat([