Skip to content

Commit c3341bf

Browse files
committed
Refactor CORS header handling to simplify origin validation logic in HTTP server
1 parent 946f8af commit c3341bf

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,8 @@ if (useHttp) {
303303
}
304304

305305
// Set CORS headers for valid origins
306-
if (origin && isValidOrigin) {
307-
res.setHeader('Access-Control-Allow-Origin', origin)
308-
} else {
309-
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000')
310-
}
306+
// Note: origin is guaranteed to be truthy here because isValidOrigin === true
307+
res.setHeader('Access-Control-Allow-Origin', origin!)
311308
res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS')
312309
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Accept')
313310

0 commit comments

Comments
 (0)