Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// NOTE: related to src/configs/rewrites.ts
export const DOCUMENTATION_DOMAIN = 'e2b-docs.dev'

/** @type {import('next').NextConfig} */
const config = {
eslint: {
Expand Down Expand Up @@ -42,8 +45,8 @@ const config = {
],
},
],
rewrites: async () => {
return [
rewrites: async () => ({
beforeFiles: [
{
source: "/ph-proxy/static/:path*",
destination: "https://us-assets.i.posthog.com/static/:path*",
Expand All @@ -52,8 +55,18 @@ const config = {
source: "/ph-proxy/:path*",
destination: "https://us.i.posthog.com/:path*",
},
]
},

// Asset rewrites for Mintlify
{
source: '/mintlify-assets/:path*',
destination: `https://${DOCUMENTATION_DOMAIN}/mintlify-assets/:path*`,
},
{
source: '/_mintlify/:path*',
destination: `https://${DOCUMENTATION_DOMAIN}/_mintlify/:path*`,
},
],
}),
redirects: async () => [
{
source: '/docs/api/cli',
Expand Down
11 changes: 9 additions & 2 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

import { ALLOW_SEO_INDEXING } from '@/configs/flags'
import {
DOCS_NEXT_DOMAIN,
LANDING_PAGE_DOMAIN,
ROUTE_REWRITE_CONFIG,
SDK_REFERENCE_DOMAIN,
} from '@/configs/rewrites'
import { DomainConfig } from '@/types/rewrites.types'
import { XMLParser } from 'fast-xml-parser'
import { MetadataRoute } from 'next'
import { DOCUMENTATION_DOMAIN } from '../../next.config.mjs'

// Cache the sitemap for 15 minutes (in seconds)
const SITEMAP_CACHE_TIME = 15 * 60
Expand Down Expand Up @@ -56,7 +57,13 @@ const sites: Site[] = [
baseUrl: 'https://e2b.dev',
},
{
sitemapUrl: `https://${DOCS_NEXT_DOMAIN}/sitemap.xml`,
sitemapUrl: `https://${SDK_REFERENCE_DOMAIN}/sitemap.xml`,
priority: 0.7,
changeFrequency: 'weekly',
baseUrl: 'https://e2b.dev',
},
{
sitemapUrl: `https://${DOCUMENTATION_DOMAIN}/sitemap.xml`,
priority: 0.9,
changeFrequency: 'weekly',
baseUrl: 'https://e2b.dev',
Expand Down
30 changes: 26 additions & 4 deletions src/configs/rewrites.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { DomainConfig } from '@/types/rewrites.types'

export const LANDING_PAGE_DOMAIN = 'www.e2b-landing-page.com'
export const DOCS_NEXT_DOMAIN = 'e2b-docs.vercel.app'
export const SDK_REFERENCE_DOMAIN = 'e2b-docs.vercel.app'
// NOTE: DOCUMENTATION_DOMAIN has to be defined in next.config.mjs, such that we are able to use it there
import { DOCUMENTATION_DOMAIN } from '../../next.config.mjs'

// Currently we have two locations for rewrites to happen.

Expand Down Expand Up @@ -36,10 +38,30 @@ export const ROUTE_REWRITE_CONFIG: DomainConfig[] = [
},
]

// Middleware native rewrite config
/**
* Middleware native rewrite config
*
* We implement rewrites directly in middleware rather than using Next.js's built-in
* `rewrites` configuration in next.config.js due to Cloudflare WAF compatibility issues.
*
* Context: Next.js's native rewrite system seemed to use the `x-middleware-subrequest` header
* internally, which triggered Cloudflare's managed WAF rules designed to mitigate
* CVE-2025-29927 (Next.js authentication bypass vulnerability). This causes legitimate
* rewrite requests to be blocked when the WAF rule is enabled.
*
* By handling rewrites directly in our middleware layer and controlling the headers, we avoid using the internal
* header mechanism and prevent false positives from Cloudflare's security filters.
*
* @see https://developers.cloudflare.com/changelog/2025-03-22-next-js-vulnerability-waf/
* TODO: Re-evaluate if this workaround is still necessary after Cloudflare updates their WAF rules
*/
export const MIDDLEWARE_REWRITE_CONFIG: DomainConfig[] = [
{
domain: DOCS_NEXT_DOMAIN,
rules: [{ path: '/docs' }],
domain: SDK_REFERENCE_DOMAIN,
rules: [{ path: '/docs/sdk-reference' }],
},
{
domain: DOCUMENTATION_DOMAIN,
rules: [{ path: '/docs' }, { path: '/mcp' }],
},
]
10 changes: 8 additions & 2 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@ export async function middleware(request: NextRequest) {
headers.set('x-e2b-should-index', '1')
}

return NextResponse.rewrite(rewriteUrl, {
const response = NextResponse.rewrite(rewriteUrl, {
request: {
headers,
},
})

if (ALLOW_SEO_INDEXING) {
response.headers.set('X-Robots-Tag', 'index, follow')
}

return response
}

// Setup response and Supabase client
Expand Down Expand Up @@ -131,6 +137,6 @@ export const config = {
* - vercel analytics route
* - posthog routes
*/
'/((?!_next/static|_next/image|favicon.ico|api/|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$|_vercel/|ingest/|ph-proxy/|array/).*)',
'/((?!_next/static|_next/image|favicon.ico|api/|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$|_vercel/|ingest/|ph-proxy/|array/|mintlify-assets/|_mintlify/).*)',
],
}
Loading