2
0

🔧 Fix landing page loading issue with query params

Closes #1560
This commit is contained in:
Baptiste Arnaud
2024-06-11 10:03:40 +02:00
parent fdbd9c08a3
commit 40ca02df8c

View File

@ -37,8 +37,23 @@ const landingPagePaths = [
'/about', '/about',
'/oss-friends', '/oss-friends',
'/blog', '/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} */ /** @type {import('next').NextConfig} */
const nextConfig = { const nextConfig = {
reactStrictMode: true, reactStrictMode: true,
@ -72,39 +87,39 @@ const nextConfig = {
async rewrites() { async rewrites() {
return { return {
beforeFiles: (process.env.LANDING_PAGE_URL beforeFiles: (process.env.LANDING_PAGE_URL
? landingPagePaths ? landingPageReferers
.map((path) => ({ .map((path) => ({
source: '/_next/static/:static*', source: '/_next/static/:static*',
has: [ has: [
{ {
type: 'header', type: 'header',
key: 'referer', key: 'referer',
value: `https://typebot.io${path}`, value: `${currentOrigin}${path}${optionalQueryParams}`,
}, },
], ],
destination: `${process.env.LANDING_PAGE_URL}/_next/static/:static*`, destination: `${process.env.LANDING_PAGE_URL}/_next/static/:static*`,
})) }))
.concat( .concat(
landingPagePaths.map((path) => ({ landingPageReferers.map((path) => ({
source: '/typebots/:typebot*', source: '/typebots/:typebot*',
has: [ has: [
{ {
type: 'header', type: 'header',
key: 'referer', key: 'referer',
value: `https://typebot.io${path}`, value: `${currentOrigin}${path}${optionalQueryParams}`,
}, },
], ],
destination: `${process.env.LANDING_PAGE_URL}/typebots/:typebot*`, destination: `${process.env.LANDING_PAGE_URL}/typebots/:typebot*`,
})) }))
) )
.concat( .concat(
landingPagePaths.map((path) => ({ landingPageReferers.map((path) => ({
source: '/styles/:style*', source: '/styles/:style*',
has: [ has: [
{ {
type: 'header', type: 'header',
key: 'referer', key: 'referer',
value: `https://typebot.io${path}`, value: `${currentOrigin}${path}${optionalQueryParams}`,
}, },
], ],
destination: `${process.env.LANDING_PAGE_URL}/styles/:style*`, destination: `${process.env.LANDING_PAGE_URL}/styles/:style*`,
@ -116,79 +131,25 @@ const nextConfig = {
has: [ has: [
{ {
type: 'host', type: 'host',
value: 'typebot.io', value: currentHost,
}, },
], ],
destination: `${process.env.LANDING_PAGE_URL}${path}`, destination: `${process.env.LANDING_PAGE_URL}${path}`,
})) }))
) )
.concat([ .concat(
{ landingPageReferers.map((path) => ({
source: '/blog/:slug', source: '/images/:image*',
has: [
{
type: 'host',
value: 'typebot.io',
},
],
destination: `${process.env.LANDING_PAGE_URL}/blog/:slug`,
},
{
source: '/_next/static/:static*',
has: [ has: [
{ {
type: 'header', type: 'header',
key: 'referer', key: 'referer',
value: `https://typebot.io/blog/(?<slug>.*)`, value: `${currentOrigin}${path}${optionalQueryParams}`,
}, },
], ],
destination: `${process.env.LANDING_PAGE_URL}/_next/static/:static*`, destination: `${process.env.LANDING_PAGE_URL}/images/:image*`,
}, }))
{ )
source: '/images/blog/:images*',
has: [
{
type: 'header',
key: 'referer',
value: `https://typebot.io/blog/(?<slug>.*)`,
},
],
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/(?<slug>.*)`,
},
],
destination: `${process.env.LANDING_PAGE_URL}/typebots/:typebot*`,
},
{
source: '/styles/:style*',
has: [
{
type: 'header',
key: 'referer',
value: `https://typebot.io/blog/(?<slug>.*)`,
},
],
destination: `${process.env.LANDING_PAGE_URL}/styles/:style*`,
},
])
: [] : []
) )
.concat([ .concat([