diff --git a/next.config.mjs b/next.config.mjs index d3edbd380..a355fc8ed 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,3 +1,6 @@ +// NOTE: related to src/configs/rewrites.ts +export const DOCUMENTATION_DOMAIN = 'e2b.mintlify.app' + /** @type {import('next').NextConfig} */ const config = { eslint: { @@ -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*", @@ -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', diff --git a/src/app/sitemap.ts b/src/app/sitemap.ts index caa9b9307..25b8ea1b7 100644 --- a/src/app/sitemap.ts +++ b/src/app/sitemap.ts @@ -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 @@ -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', diff --git a/src/configs/rewrites.ts b/src/configs/rewrites.ts index 37a2530ee..7cbb0a503 100644 --- a/src/configs/rewrites.ts +++ b/src/configs/rewrites.ts @@ -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. @@ -36,10 +38,29 @@ 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 because we need to set custom request + * and response headers for these rewritten requests. + * + * Specifically, we need to: + * - Add custom headers to the request (e.g., x-e2b-should-index for SEO control) + * - Set custom response headers (e.g., X-Robots-Tag for search engine indexing) + * - Have fine-grained control over the rewrite behavior based on environment variables + * + * Next.js's native rewrite configuration doesn't provide this level of header manipulation + * capability, so we handle these rewrites in our middleware layer where we have full + * control over the request/response cycle. + */ 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' }], }, ] diff --git a/src/middleware.ts b/src/middleware.ts index 4903c2210..d2a1209a5 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -62,11 +62,19 @@ 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') + } else { + response.headers.set('X-Robots-Tag', 'noindex, nofollow') + } + + return response } // Setup response and Supabase client @@ -131,6 +139,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/).*)', ], }