Skip to content

Commit 5ee3714

Browse files
ValentaTomasben-fornefeld
authored andcommitted
fix: clean up middleware rewrite fetch + use next native rewrite response + prefix landing page hostname with www
Simplify fetch Remove headers Add rest of headers Explicitly define fetch options Remove header manipulation Test all custom config Remove out cache header Remove no cache in header Remove cache Tweak fetch options Remove credentials Remove referrer Return to basic setup Add redirect handling Stop caching Remove redirect Remove no cache Return old settings Proxy everything Modify hostname Change domain Change hostname back Remove caching Change rewrite mechanism Add more headers Remove the rewrite Follow redirect Try www Add log Try just rewrite Only pass get requests Fix error Change headers passing Print headers Test pure rewrite Remove unused code Add html replace for ai agents list Remove logs
1 parent 4453b26 commit 5ee3714

2 files changed

Lines changed: 24 additions & 13 deletions

File tree

apps/web/src/app/hostnames.ts

Lines changed: 1 addition & 1 deletion
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

Lines changed: 23 additions & 12 deletions
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)