Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Changes from 1 commit
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
Prev Previous commit
chore: check cors header in probe response
  • Loading branch information
2color committed Jul 17, 2025
commit ebb81b8420639f0d60d99f781f86148eee86a227
6 changes: 5 additions & 1 deletion packages/routers/src/http-gateway-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ class HTTPGatewayRouter implements Partial<Routing> {
method: 'GET',
mode: 'cors'
})
return response.ok || response.status === 404

const corsHeaders = response.headers.get('access-control-allow-origin')
const hasCors = corsHeaders === '*' || corsHeaders?.includes(window.location.origin)
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code assumes it's running in a browser environment by accessing window.location.origin, but this router may be used in Node.js environments where window is undefined. This will cause a runtime error in non-browser environments.

Suggested change
const hasCors = corsHeaders === '*' || corsHeaders?.includes(window.location.origin)
const origin = (typeof window !== 'undefined' && window.location?.origin) || ''
const hasCors = corsHeaders === '*' || corsHeaders?.includes(origin)

Copilot uses AI. Check for mistakes.


Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for accepting 404 status as a valid response should be documented. It's not immediately clear why a 404 response indicates CORS support.

Suggested change
// Some HTTP gateways may return a 404 status for non-existent resources while still supporting CORS.
// The presence of CORS headers is the primary determinant of CORS support, and a 404 status is treated
// as valid in this context to account for such behavior.

Copilot uses AI. Check for mistakes.

return hasCors && (response.ok || response.status === 404)
} catch (error) {
return false
}
Expand Down
Loading