Skip to content

Commit

Permalink
Redirect landing page to new webflow hosting
Browse files Browse the repository at this point in the history
  • Loading branch information
mlejva committed Dec 6, 2024
1 parent 786fcd8 commit ff8f0ab
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
5 changes: 5 additions & 0 deletions apps/web/src/app/hostnames.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// We are in the process of migrating to the new landing page hosting.
export const landingPageWebflowHostname = 'e2b-dev.webflow.io'
export const landingPageFramerHostname = 'e2b-landing-page.framer.website'
export const blogFramerHostname = 'e2b-blog.framer.website'
export const changelogFramerHostname = 'e2b-changelog.framer.website'
6 changes: 3 additions & 3 deletions apps/web/src/app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MetadataRoute } from 'next'
import { XMLParser } from 'fast-xml-parser'
import { replaceUrls } from '@/utils/replaceUrls'
import path from 'path'
import { replaceUrls } from '@/utils/replaceUrls'
import { getPageForSitemap } from '@/utils/sitemap'

type ChangeFrequency =
Expand Down Expand Up @@ -57,7 +57,7 @@ async function getXmlData(url: string): Promise<Sitemap> {
const response = await fetch(url, { cache: 'no-cache' })

if (!response.ok) {
return { urlset: { url: [] }}
return { urlset: { url: [] } }
}

const text = await response.text()
Expand Down Expand Up @@ -99,7 +99,7 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {


const dashboardPath = path.join(process.cwd(), 'src', 'app', '(dashboard)', 'dashboard')
const dashboardPages = getPageForSitemap(dashboardPath, 'https://e2b.dev/dashboard/', 0.5)
const dashboardPages = getPageForSitemap(dashboardPath, 'https://e2b.dev/dashboard/', 0.5)

const docsDirectory = path.join(process.cwd(), 'src', 'app', '(docs)', 'docs')
const docsPages = getPageForSitemap(docsDirectory, 'https://e2b.dev/docs/', 0.5).filter(
Expand Down
26 changes: 16 additions & 10 deletions apps/web/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { NextRequest, NextResponse } from 'next/server'
import { replaceUrls } from '@/utils/replaceUrls'
import {
landingPageWebflowHostname,
landingPageFramerHostname,
blogFramerHostname,
changelogFramerHostname,
} from '@/app/hostnames'

export async function middleware(req: NextRequest): Promise<NextResponse> {
if (req.method !== 'GET') return NextResponse.next()
Expand All @@ -11,43 +17,43 @@ export async function middleware(req: NextRequest): Promise<NextResponse> {

if (url.pathname === '' || url.pathname === '/') {
if (process.env.NODE_ENV === 'production') {
url.hostname = 'e2b-landing-page.framer.website'
url.hostname = landingPageWebflowHostname
} else {
return NextResponse.redirect(new URL('/dashboard', req.url))
}
}

if (url.pathname.startsWith('/terms')) {
url.hostname = 'e2b-landing-page.framer.website'
url.hostname = landingPageWebflowHostname
}

if (url.pathname.startsWith('/privacy')) {
url.hostname = 'e2b-landing-page.framer.website'
url.hostname = landingPageWebflowHostname
}

if (url.pathname.startsWith('/pricing')) {
url.hostname = 'e2b-landing-page.framer.website'
url.hostname = landingPageWebflowHostname
}

// TODO: Not on the new landing page hosting yet
if (url.pathname.startsWith('/ai-agents')) {
url.hostname = 'e2b-landing-page.framer.website'
url.hostname = landingPageFramerHostname
}

if (url.pathname === '/blog' || url.pathname === '/blog/') {
url.pathname = '/'
url.hostname = 'e2b-blog.framer.website'
url.hostname = blogFramerHostname
}

if (url.pathname.startsWith('/blog')) {
url.hostname = 'e2b-blog.framer.website'
url.hostname = blogFramerHostname
}

if (url.pathname === '/changelog' || url.pathname === '/changelog/') {
url.pathname = '/'
url.hostname = 'e2b-changelog.framer.website'
url.hostname = changelogFramerHostname
}
if (url.pathname.startsWith('/changelog')) {
url.hostname = 'e2b-changelog.framer.website'
url.hostname = changelogFramerHostname
}

const res = await fetch(url.toString(), { ...req })
Expand Down
19 changes: 15 additions & 4 deletions apps/web/src/utils/replaceUrls.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
import {
landingPageWebflowHostname,
landingPageFramerHostname,
blogFramerHostname,
changelogFramerHostname,
} from '@/app/hostnames'

export function replaceUrls(text: string, urlPathName: string, prefix: string = '', suffix: string = ''): string {
const pattern = suffix ? `(?<url>${prefix}https://e2b-[^${suffix}]*)/${suffix}` : `(?<url>${prefix}https://e2b-.*)/$`

return text.replaceAll(
new RegExp(pattern, 'g'),
new RegExp(pattern, 'g'),
(_, url) => url + suffix,
)
.replaceAll(
`${prefix}${landingPageWebflowHostname}`,
`${prefix}https://e2b.dev`
)
.replaceAll(
`${prefix}https://e2b-landing-page.framer.website`,
`${prefix}${landingPageFramerHostname}`,
`${prefix}https://e2b.dev`
)
.replaceAll(
`${prefix}https://e2b-blog.framer.website`,
`${prefix}${blogFramerHostname}`,
// The default url on framer does not have /blog in the path but the custom domain does,
// so we need to handle this explicitly.
urlPathName === '/'
? `${prefix}https://e2b.dev/blog`
: `${prefix}https://e2b.dev`
)
.replaceAll(
`${prefix}https://e2b-changelog.framer.website`,
`${prefix}${changelogFramerHostname}`,
// The default url on framer does not have /changelog in the path but the custom domain does,
// so we need to handle this explicitly.
urlPathName === '/'
Expand Down

0 comments on commit ff8f0ab

Please sign in to comment.