Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
fix: clean up middleware rewrite fetch + use next native rewrite response + prefix landing page hostname with www
Tomas Valenta5ee371498add
diff --git a/apps/web/src/app/hostnames.ts b/apps/web/src/app/hostnames.tsindex 1ee4e0893..3abc62e1c 100644--- a/apps/web/src/app/hostnames.ts+++ b/apps/web/src/app/hostnames.ts@@ -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'diff --git a/apps/web/src/middleware.ts b/apps/web/src/middleware.tsindex 344dac7cb..01e6310ee 100644--- a/apps/web/src/middleware.ts+++ b/apps/web/src/middleware.ts@@ -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()@@ -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 yetif (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,})}@@ -80,4 +91,4 @@ export const config = {'/pricing/:path*','/cookbook/:path*',],-}+}\ No newline at end of file