Skip to content

Commit c4129d8

Browse files
Fix Webflow proxying with www-prefixed hostname and proper request handling (e2b-dev#634)
This PR resolves the Cloudflare IP blocking issue by: 1. Adding www prefix to landing page hostname 2. Properly handling request headers with new Headers object 3. Adding redirect handling to follow redirects 4. Refactoring middleware response handling for proper URL rewriting These changes prevent Cloudflare from identifying our requests as suspicious automated traffic while maintaining the functionality of our proxy middleware.
2 parents 4453b26 + 5ee3714 commit c4129d8

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

apps/web/src/app/hostnames.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// We are in the process of migrating to the new landing page hosting.
2-
export const landingPageHostname = 'e2b-landing-page.com'
2+
export const landingPageHostname = 'www.e2b-landing-page.com'
33
export const landingPageFramerHostname = 'e2b-landing-page.framer.website'
44
export const blogFramerHostname = 'e2b-blog.framer.website'
55
export const changelogFramerHostname = 'e2b-changelog.framer.website'

apps/web/src/middleware.ts

+23-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NextRequest, NextResponse } from 'next/server'
2-
import { replaceUrls } from '@/utils/replaceUrls'
32
import { landingPageHostname, landingPageFramerHostname } from '@/app/hostnames'
3+
import { replaceUrls } from '@/utils/replaceUrls'
44

55
export async function middleware(req: NextRequest): Promise<NextResponse> {
66
if (req.method !== 'GET') return NextResponse.next()
@@ -48,23 +48,34 @@ export async function middleware(req: NextRequest): Promise<NextResponse> {
4848
}
4949
}
5050

51+
const headers = new Headers(req.headers)
52+
5153
// TODO: Not on the new landing page hosting yet
5254
if (url.pathname.startsWith('/ai-agents')) {
5355
url.hostname = landingPageFramerHostname
54-
}
5556

56-
const res = await fetch(url.toString(), { ...req })
57+
const res = await fetch(url.toString(), {
58+
...req,
59+
headers,
60+
redirect: 'follow',
61+
})
5762

58-
const htmlBody = await res.text()
63+
const htmlBody = await res.text()
5964

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

63-
return new NextResponse(modifiedHtmlBody, {
64-
status: res.status,
65-
statusText: res.statusText,
66-
headers: res.headers,
67-
url: req.url,
68+
return new NextResponse(modifiedHtmlBody, {
69+
status: res.status,
70+
statusText: res.statusText,
71+
headers: res.headers,
72+
url: req.url,
73+
})
74+
}
75+
76+
return NextResponse.rewrite(url.toString(), {
77+
...req,
78+
headers,
6879
})
6980
}
7081

@@ -80,4 +91,4 @@ export const config = {
8091
'/pricing/:path*',
8192
'/cookbook/:path*',
8293
],
83-
}
94+
}

0 commit comments

Comments
 (0)