Skip to content

Commit

Permalink
Revert "Redirect the root URL route to new Webflow hosting"
Browse files Browse the repository at this point in the history
  • Loading branch information
mlejva authored Dec 6, 2024
1 parent b416c63 commit 7b295de
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5,504 deletions.
5 changes: 0 additions & 5 deletions apps/web/src/app/hostnames.ts

This file was deleted.

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 path from 'path'
import { replaceUrls } from '@/utils/replaceUrls'
import path from 'path'
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
32 changes: 11 additions & 21 deletions apps/web/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
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 @@ -17,43 +11,43 @@ export async function middleware(req: NextRequest): Promise<NextResponse> {

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

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

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

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

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

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

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

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

const res = await fetch(url.toString(), { ...req })
Expand All @@ -62,12 +56,8 @@ export async function middleware(req: NextRequest): Promise<NextResponse> {

// !!! NOTE: Replace has intentionally not completed quotes to catch the rest of the path !!!
const modifiedHtmlBody = replaceUrls(htmlBody, url.pathname, 'href="', '">')
// Even though we are paying for a Webflow tier that allows us to remove the badge, it doesn't work.
// eslint-disable-next-line
const scriptRegex = /<script src="https:\/\/cdn\.prod\.website-files\.com\/[^\"]*\.js" type="text\/javascript"><\/script>/g
const cleanedHtmlBody = modifiedHtmlBody.replace(scriptRegex, '')

return new NextResponse(cleanedHtmlBody, {
return new NextResponse(modifiedHtmlBody, {
status: res.status,
statusText: res.statusText,
headers: res.headers,
Expand Down
19 changes: 4 additions & 15 deletions apps/web/src/utils/replaceUrls.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
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}${landingPageFramerHostname}`,
`${prefix}https://e2b-landing-page.framer.website`,
`${prefix}https://e2b.dev`
)
.replaceAll(
`${prefix}${blogFramerHostname}`,
`${prefix}https://e2b-blog.framer.website`,
// 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}${changelogFramerHostname}`,
`${prefix}https://e2b-changelog.framer.website`,
// 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
Loading

0 comments on commit 7b295de

Please sign in to comment.