Allow baseUrl in DOM Components for the Origin Header with CORS
M
Marco Luz
Currently, when using DOM-based components (with "use dom" directive) in an Expo project, the Origin header is automatically set based on the execution environment. This can cause CORS issues when interacting with APIs that require a consistent Origin value.
We propose adding support for a configurable baseUrl option in DOM components, allowing developers to explicitly define the base URL for requests. This would enable consistent Origin headers, improving compatibility with APIs that enforce strict CORS policies.
Use Case
• Developers using Expo WebView or fetch to communicate with backend APIs that require a fixed Origin.
• Handling authentication flows where a specific Origin is expected.
• Ensuring uniform behavior between development and production environments.
Proposed Solution
Introduce a baseUrl configuration option for relevant DOM-based components, allowing developers to override the default Origin header. This setting would be respected when making requests via fetch, WebView, or other applicable components.
Evan Bacon
I recommend using native actions to make fetch requests from the native runtime instead of battling with CORS in a webview. Alternatively, you can setup API routes to proxy requests like a modern website would.