Skip to content
Merged
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
2 changes: 1 addition & 1 deletion apps/web/src/app/hostnames.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// We are in the process of migrating to the new landing page hosting.
export const landingPageHostname = 'e2b-landing-page.com'
export const landingPageHostname = 'www.e2b-landing-page.com'
export const landingPageFramerHostname = 'e2b-landing-page.framer.website'
export const blogFramerHostname = 'e2b-blog.framer.website'
export const changelogFramerHostname = 'e2b-changelog.framer.website'
35 changes: 23 additions & 12 deletions apps/web/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextRequest, NextResponse } from 'next/server'
import { replaceUrls } from '@/utils/replaceUrls'
import { landingPageHostname, landingPageFramerHostname } from '@/app/hostnames'
import { replaceUrls } from '@/utils/replaceUrls'

export async function middleware(req: NextRequest): Promise<NextResponse> {
if (req.method !== 'GET') return NextResponse.next()
Expand Down Expand Up @@ -48,23 +48,34 @@ export async function middleware(req: NextRequest): Promise<NextResponse> {
}
}

const headers = new Headers(req.headers)

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

const res = await fetch(url.toString(), { ...req })
const res = await fetch(url.toString(), {
...req,
headers,
redirect: 'follow',
})

const htmlBody = await res.text()
const htmlBody = await res.text()

// !!! NOTE: Replace has intentionally not completed quotes to catch the rest of the path !!!
const modifiedHtmlBody = replaceUrls(htmlBody, url.pathname, 'href="', '">')
// !!! NOTE: Replace has intentionally not completed quotes to catch the rest of the path !!!
const modifiedHtmlBody = replaceUrls(htmlBody, url.pathname, 'href="', '">')

return new NextResponse(modifiedHtmlBody, {
status: res.status,
statusText: res.statusText,
headers: res.headers,
url: req.url,
return new NextResponse(modifiedHtmlBody, {
status: res.status,
statusText: res.statusText,
headers: res.headers,
url: req.url,
})
}

return NextResponse.rewrite(url.toString(), {
...req,
headers,
})
}

Expand All @@ -80,4 +91,4 @@ export const config = {
'/pricing/:path*',
'/cookbook/:path*',
],
}
}
Loading