Skip to content

Add NO_INDEX & VERBOSE flags #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 7 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ NEXT_PUBLIC_DEFAULT_API_DOMAIN=e2b.dev
# ZeroBounce API key for email validation
# ZEROBOUNCE_API_KEY=

# Set to 1 to enable no-indexing
# NO_INDEX=0

# =================================
# OPTIONAL CLIENT ENVIRONMENT VARIABLES
# =================================
Expand All @@ -61,4 +64,7 @@ NEXT_PUBLIC_DEFAULT_API_DOMAIN=e2b.dev
# NEXT_PUBLIC_SCAN=0

# Set to 1 to use mock data
# NEXT_PUBLIC_MOCK_DATA=0
# NEXT_PUBLIC_MOCK_DATA=0

# Set to 1 to enable verbose logging
# NEXT_PUBLIC_VERBOSE=0
20 changes: 20 additions & 0 deletions src/app/(rewrites)/[[...slug]]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ERROR_CODES } from '@/configs/logs'
import { NextRequest } from 'next/server'
import sitemap from '@/app/sitemap'
import { BASE_URL } from '@/configs/urls'
import { NO_INDEX } from '@/lib/utils/flags'

export const revalidate = 900
export const dynamic = 'force-static'
Expand Down Expand Up @@ -80,6 +81,25 @@ export async function GET(request: NextRequest): Promise<Response> {
const newHeaders = new Headers(res.headers)
newHeaders.delete('content-encoding')

// take precautions if NO_INDEX is set
if (NO_INDEX) {
// add noindex header
newHeaders.set('X-Robots-Tag', 'noindex, nofollow')
// remove any existing robots meta tags and add our own
const modifiedHtml = modifiedHtmlBody
.replace(/<meta[^>]*name=["']robots["'][^>]*>/gi, '')
.replace(
/<head[^>]*>/i,
(match) =>
`${match}<meta name="robots" content="noindex, nofollow">`
)

return new Response(modifiedHtml, {
status: res.status,
headers: newHeaders,
})
}

return new Response(modifiedHtmlBody, {
status: res.status,
headers: newHeaders,
Expand Down
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Toaster } from '@/ui/primitives/toaster'
import Head from 'next/head'
import { GTMHead } from '@/features/google-tag-manager'
import { Analytics } from '@vercel/analytics/next'
import { NO_INDEX } from '@/lib/utils/flags'

export const metadata: Metadata = {
metadataBase: new URL(BASE_URL),
Expand All @@ -28,6 +29,7 @@ export const metadata: Metadata = {
title: METADATA.title,
description: METADATA.description,
},
robots: NO_INDEX ? 'noindex, nofollow' : 'index, follow',
}

export default function RootLayout({
Expand Down
6 changes: 6 additions & 0 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
LANDING_PAGE_FRAMER_DOMAIN,
} from '@/configs/domains'
import { BLOG_FRAMER_DOMAIN } from '@/configs/domains'
import { NO_INDEX } from '@/lib/utils/flags'

// Cache the sitemap for 24 hours (in seconds)
const SITEMAP_CACHE_TIME = 24 * 60 * 60
Expand Down Expand Up @@ -168,6 +169,11 @@ async function getSitemap(site: Site): Promise<MetadataRoute.Sitemap> {
* @returns Complete sitemap for the E2B website
*/
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
// Return empty sitemap if NO_INDEX is set
if (NO_INDEX) {
return []
}

let mergedSitemap: MetadataRoute.Sitemap = []

// Fetch sitemaps from all configured sites (Webflow & Framer sites + docs)
Expand Down
28 changes: 20 additions & 8 deletions src/features/dashboard/sandboxes/table-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useTemplateTableStore } from '../templates/stores/table-store'
import { useServerContext } from '@/lib/hooks/use-server-context'
import { JsonPopover } from '@/ui/json-popover'
import posthog from 'posthog-js'
import { logError } from '@/lib/clients/logger'

export type SandboxWithMetrics = Sandbox & { metrics: SandboxMetrics[] }

Expand All @@ -40,14 +41,25 @@ export const fuzzyFilter: FilterFn<Sandbox> = (
value,
addMeta
) => {
if (columnId === 'metadata') {
const metadata = row.original.metadata

if (!metadata) return false

const stringifiedMetadata = JSON.stringify(metadata)

return stringifiedMetadata.includes(value)
// try catch to avoid crash by serialization issues
try {
if (columnId === 'metadata') {
const metadata = row.original.metadata

if (!metadata) return false

const stringifiedMetadata = JSON.stringify(metadata)

return stringifiedMetadata.includes(value)
}
} catch (error) {
logError('Error in fuzzyFilter', {
error,
row,
columnId,
value,
})
return false
}

const itemRank = rankItem(row.getValue(columnId), value)
Expand Down
7 changes: 4 additions & 3 deletions src/lib/clients/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { z } from 'zod'
import { UnknownError } from '@/types/errors'
import { logDebug, logError, logSuccess } from './logger'
import { ActionError } from '../utils/action'
import { VERBOSE } from '../utils/flags'

export const actionClient = createSafeActionClient({
handleServerError(e) {
Expand Down Expand Up @@ -31,7 +32,7 @@ export const actionClient = createSafeActionClient({
defaultValidationErrorsShape: 'flattened',
}).use(async ({ next, clientInput, metadata }) => {
let startTime
if (process.env.NODE_ENV === 'development') {
if (VERBOSE) {
startTime = performance.now()
}

Expand All @@ -56,14 +57,14 @@ export const actionClient = createSafeActionClient({
result: rest,
input: clientInput,
})
} else if (process.env.NODE_ENV === 'development') {
} else if (VERBOSE) {
logSuccess(`${actionOrFunction} '${actionOrFunctionName}' succeeded:`, {
result: rest,
input: clientInput,
})
}

if (process.env.NODE_ENV === 'development' && startTime) {
if (VERBOSE && startTime) {
const endTime = performance.now()
logDebug(
`${actionOrFunction} '${actionOrFunctionName}' execution took ${endTime - startTime} ms`
Expand Down
2 changes: 2 additions & 0 deletions src/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { z } from 'zod'
export const serverSchema = z.object({
SUPABASE_SERVICE_ROLE_KEY: z.string().min(1),
COOKIE_ENCRYPTION_KEY: z.string().min(32),
NO_INDEX: z.string().optional(),

BILLING_API_URL: z.string().url().optional(),
DEVELOPMENT_INFRA_API_DOMAIN: z.string().optional(),
Expand All @@ -25,6 +26,7 @@ export const clientSchema = z.object({
NEXT_PUBLIC_EXPOSE_STORYBOOK: z.string().optional(),
NEXT_PUBLIC_SCAN: z.string().optional(),
NEXT_PUBLIC_MOCK_DATA: z.string().optional(),
NEXT_PUBLIC_VERBOSE: z.string().optional(),
})

export const testEnvSchema = z.object({
Expand Down
4 changes: 4 additions & 0 deletions src/lib/utils/flags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const NO_INDEX = process.env.NO_INDEX === '1'
export const VERBOSE =
process.env.NODE_ENV === 'development' ||
process.env.NEXT_PUBLIC_VERBOSE === '1'