Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Replace urls in sitemap

Jakub Novak54a1b9390830
diff --git a/apps/docs/src/app/sitemap.ts b/apps/docs/src/app/sitemap.ts
index 3dce01fbe..73872754f 100644
--- a/apps/docs/src/app/sitemap.ts
+++ b/apps/docs/src/app/sitemap.ts
@@ -7,7 +7,7 @@ export default function sitemap(): MetadataRoute.Sitemap {
const mdxFilePaths = getAllMdxFilePaths(appDirectory)
const priority = 0.5
- const sitemap = mdxFilePaths
+ return mdxFilePaths
.map((filePath) => {
const pathname = path
.relative(appDirectory, filePath)
@@ -24,8 +24,6 @@ export default function sitemap(): MetadataRoute.Sitemap {
}
})
.filter(Boolean)
-
- return sitemap
}
function getAllMdxFilePaths(directory: string): string[] {
diff --git a/apps/reverse-proxy/app/sitemap.ts b/apps/reverse-proxy/app/sitemap.ts
index 8432c8c49..6d7eb23d9 100644
--- a/apps/reverse-proxy/app/sitemap.ts
+++ b/apps/reverse-proxy/app/sitemap.ts
@@ -1,5 +1,6 @@
import { MetadataRoute } from 'next'
import { XMLParser } from 'fast-xml-parser'
+import { replaceUrls } from '@/utils/replaceUrls'
type ChangeFrequency =
| 'always'
@@ -77,7 +78,7 @@ async function getSitemap(
if (Array.isArray(data.urlset.url)) {
return data.urlset.url.map((line) => {
return {
- url: line.loc,
+ url: replaceUrls(line.loc, line.loc, "<loc>", "<"),
priority: line?.priority || priority,
changeFrequency: line?.changefreq || changeFrequency,
}
diff --git a/apps/reverse-proxy/middleware.ts b/apps/reverse-proxy/middleware.ts
index 15497ab58..f6e223e1a 100644
--- a/apps/reverse-proxy/middleware.ts
+++ b/apps/reverse-proxy/middleware.ts
@@ -1,4 +1,5 @@
import { NextRequest, NextResponse } from 'next/server'
+import { replaceUrls } from '@/utils/replaceUrls'
export async function middleware(req: NextRequest): Promise<NextResponse> {
if (req.method !== 'GET') return NextResponse.next()
@@ -34,30 +35,7 @@ export async function middleware(req: NextRequest): Promise<NextResponse> {
const htmlBody = await res.text()
// !!! NOTE: Replace has intentionally not completed quotes to catch the rest of the path !!!
- const modifiedHtmlBody = htmlBody.replaceAll(
- /href="https:\/\/e2b-[^"]*"/g,
- match => match.replace(/\/"$/, '"'),
- )
- .replaceAll(
- 'href="https://e2b-landing-page.framer.website',
- 'href="https://e2b.dev'
- )
- .replaceAll(
- 'href="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.
- url.pathname === '/'
- ? 'href="https://e2b.dev/blog'
- : 'href="https://e2b.dev'
- )
- .replaceAll(
- 'href="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.
- url.pathname === '/'
- ? 'href="https://e2b.dev/changelog'
- : 'href="https://e2b.dev'
- )
+ const modifiedHtmlBody = replaceUrls(htmlBody, url.pathname, 'href="', '"')
return new NextResponse(modifiedHtmlBody, {
status: res.status,
diff --git a/apps/reverse-proxy/utils/replaceUrls.ts b/apps/reverse-proxy/utils/replaceUrls.ts
new file mode 100644
index 000000000..20c3c9bed
--- /dev/null
+++ b/apps/reverse-proxy/utils/replaceUrls.ts
@@ -0,0 +1,26 @@
+export function replaceUrls(text: string, urlPathName: string, prefix: string, lastChar: string): string {
+ return text.replaceAll(
+ new RegExp(`${prefix}https://e2b-[^${lastChar}]*${lastChar}`, 'g'),
+ match => match.replace(new RegExp(`/${lastChar}$`), lastChar),
+ )
+ .replaceAll(
+ `${prefix}https://e2b-landing-page.framer.website`,
+ `${prefix}https://e2b.dev`
+ )
+ .replaceAll(
+ `${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}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 === '/'
+ ? `${prefix}https://e2b.dev/changelog`
+ : `${prefix}https://e2b.dev`
+ )
+}
\ No newline at end of file