import type { DeploymentRole } from '@/lib/config/deployment-role'; export function isApiPath(pathname: string): boolean { return pathname === '/api' || pathname.startsWith('/api/'); } function withoutTrailingSlash(pathname: string): string { return pathname.length > 1 ? pathname.replace(/\/+$/, '') : pathname; } /** * The Learning Engine exposes one token-protected runtime surface. Original * browser APIs remain callable internally by runtime route handlers, but are * never reachable as unauthenticated ClusterIP endpoints. */ export function shouldReturnNotFoundAtServerBoundary( role: DeploymentRole, pathname: string, method = 'GET', ): boolean { if (role !== 'server') return false; const normalized = withoutTrailingSlash(pathname); if (!isApiPath(normalized)) return true; if (normalized === '/api/runtime/v1' || normalized.startsWith('/api/runtime/v1/')) { return false; } if (normalized === '/api/internal/course-publish' && method.toUpperCase() === 'POST') { return false; } return true; }