Skip to content

Commit f8ac423

Browse files
waleedlatif1claude
andcommitted
chore(cors): restore concise TSDoc on proxy CORS helpers
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 07f0957 commit f8ac423

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

apps/sim/proxy.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ const DEFAULT_API_ALLOWED_HEADERS =
2222
const WORKFLOW_EXECUTE_HEADERS =
2323
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, X-API-Key'
2424

25+
/** Subpaths under /api/{chat,form}/* that serve the workspace UI, not embeds. */
2526
const EMBED_RESERVED_SEGMENTS = new Set(['manage', 'validate'])
2627

28+
/** True for /api/{chat,form}/[identifier] and any deeper subroute. */
2729
function isEmbedPath(pathname: string): boolean {
2830
const segments = pathname.split('/')
2931
if (segments.length < 4) return false
@@ -90,6 +92,7 @@ const CORS_RULES: readonly CorsRule[] = [
9092
},
9193
]
9294

95+
/** Single source of truth for /api/* CORS — resolved at request time, not baked at build. */
9396
export function resolveApiCorsPolicy(request: NextRequest): CorsPolicy {
9497
const { pathname } = request.nextUrl
9598
for (const rule of CORS_RULES) {
@@ -115,6 +118,7 @@ function applyCorsHeaders(response: NextResponse, policy: CorsPolicy): void {
115118
}
116119
}
117120

121+
/** Next's auto-OPTIONS doesn't carry middleware headers, so we answer preflight here. */
118122
function buildPreflightResponse(policy: CorsPolicy): NextResponse {
119123
const response = new NextResponse(null, { status: 204 })
120124
applyCorsHeaders(response, policy)

0 commit comments

Comments
 (0)