11import { createLogger } from '@sim/logger'
22import { getSessionCookie } from 'better-auth/cookies'
33import { type NextRequest , NextResponse } from 'next/server'
4- import { sendToProfound } from './lib/analytics/profound'
54import { getEnv } from './lib/core/config/env'
65import { isAuthDisabled , isDev , isHosted } from './lib/core/config/env-flags'
76import { generateRuntimeCSP } from './lib/core/security/csp'
@@ -316,40 +315,40 @@ export async function proxy(request: NextRequest) {
316315 const hasActiveSession = isAuthDisabled || ! ! sessionCookie
317316
318317 const redirect = handleRootPathRedirects ( request , hasActiveSession )
319- if ( redirect ) return track ( request , redirect )
318+ if ( redirect ) return applyIndexingPolicy ( request , redirect )
320319
321320 if ( url . pathname === '/login' || url . pathname === '/signup' ) {
322321 if ( hasActiveSession ) {
323- return track ( request , NextResponse . redirect ( new URL ( '/workspace' , request . url ) ) )
322+ return applyIndexingPolicy ( request , NextResponse . redirect ( new URL ( '/workspace' , request . url ) ) )
324323 }
325324 const response = NextResponse . next ( )
326325 response . headers . set ( 'Content-Security-Policy' , generateRuntimeCSP ( ) )
327326 response . headers . set ( 'X-Content-Type-Options' , 'nosniff' )
328327 response . headers . set ( 'X-Frame-Options' , 'SAMEORIGIN' )
329- return track ( request , response )
328+ return applyIndexingPolicy ( request , response )
330329 }
331330
332331 // Chat pages are publicly accessible embeds — CSP is set in next.config.ts headers
333332 if ( url . pathname . startsWith ( '/chat/' ) ) {
334- return track ( request , NextResponse . next ( ) )
333+ return applyIndexingPolicy ( request , NextResponse . next ( ) )
335334 }
336335
337336 if ( url . pathname . startsWith ( '/workspace' ) ) {
338337 if ( ! hasActiveSession ) {
339- return track ( request , NextResponse . redirect ( new URL ( '/login' , request . url ) ) )
338+ return applyIndexingPolicy ( request , NextResponse . redirect ( new URL ( '/login' , request . url ) ) )
340339 }
341340 const response = NextResponse . next ( )
342341 response . headers . set ( 'Content-Security-Policy' , generateRuntimeCSP ( ) )
343342 response . headers . set ( 'X-Content-Type-Options' , 'nosniff' )
344343 response . headers . set ( 'X-Frame-Options' , 'SAMEORIGIN' )
345- return track ( request , response )
344+ return applyIndexingPolicy ( request , response )
346345 }
347346
348347 const invitationRedirect = handleInvitationRedirects ( request , hasActiveSession )
349- if ( invitationRedirect ) return track ( request , invitationRedirect )
348+ if ( invitationRedirect ) return applyIndexingPolicy ( request , invitationRedirect )
350349
351350 const securityBlock = handleSecurityFiltering ( request )
352- if ( securityBlock ) return track ( request , securityBlock )
351+ if ( securityBlock ) return applyIndexingPolicy ( request , securityBlock )
353352
354353 const response = NextResponse . next ( )
355354 response . headers . set ( 'Vary' , 'User-Agent' )
@@ -358,7 +357,7 @@ export async function proxy(request: NextRequest) {
358357 response . headers . set ( 'X-Content-Type-Options' , 'nosniff' )
359358 response . headers . set ( 'X-Frame-Options' , 'SAMEORIGIN' )
360359
361- return track ( request , response )
360+ return applyIndexingPolicy ( request , response )
362361}
363362
364363/**
@@ -370,7 +369,7 @@ export async function proxy(request: NextRequest) {
370369 * the index. robots.txt is excluded from this proxy's matcher so it keeps
371370 * serving the crawlable rules this header depends on.
372371 */
373- function applyIndexingPolicy ( request : NextRequest , response : NextResponse ) : void {
372+ function applyIndexingPolicy ( request : NextRequest , response : NextResponse ) : NextResponse {
374373 const host =
375374 request . headers . get ( 'x-forwarded-host' ) ?. split ( ',' ) [ 0 ] ?. trim ( ) ||
376375 request . headers . get ( 'host' ) ||
@@ -379,14 +378,7 @@ function applyIndexingPolicy(request: NextRequest, response: NextResponse): void
379378 if ( isNonCanonicalSimHost ( host ) ) {
380379 response . headers . set ( 'X-Robots-Tag' , 'noindex, nofollow' )
381380 }
382- }
383381
384- /**
385- * Sends request data to Profound analytics (fire-and-forget) and returns the response.
386- */
387- function track ( request : NextRequest , response : NextResponse ) : NextResponse {
388- applyIndexingPolicy ( request , response )
389- sendToProfound ( request , response . status )
390382 return response
391383}
392384
0 commit comments