Allow CORS
See original GitHub issueBug description: Unable to configure CORS.
To Reproduce:
App.js
import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { WebView } from 'react-native-webview';
// ...
class MyWebComponent extends Component {
render() {
return (
<WebView
source={{uri:"file:///android_asset/index.html"}}
allowFileAccess={true}
originWhitelist={["*"]}
/>
);
}
}
android/app/src/main/assets/index.html
<script>
fetch("test.json")
.then(() => alert("got response"))
.catch(error => alert(error.message))
</script>
android/app/src/main/assets/test.json
{
"success": true
}
Expected behavior:
Able to request cross origin resource.
Environment:
- OS: Windows
- OS version: 10 Pro (1809)
- react-native version: 0.59
- react-native-webview version: 5.8.1
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:11 (1 by maintainers)
Top Results From Across the Web
Allow CORS: Access-Control-Allow-Origin
Allow CORS : Access-Control-Allow-Origin lets you easily perform cross-domain Ajax requests in web applications. Simply activate the add-on ...
Read more >Cross-Origin Resource Sharing (CORS) - MDN Web Docs
Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows a server to indicate any origins (domain, scheme, ...
Read more >CORS Enabled - W3C Wiki
Open Internet Information Service (IIS) Manager · Right click the site you want to enable CORS for and go to Properties · Change...
Read more >enable cross-origin resource sharing
enable cross-origin resource sharing. Cross-Origin Resource Sharing (CORS) is a specification that enables truly open access across domain-boundaries.
Read more >How to allow CORS in Express ? - GeeksforGeeks
Cross-Origin Resource Sharing is an HTTP-header based mechanism implemented by the browser which allows a server or an API(Application ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Some more details for my case. I followed this guide to load a local React web app bundled with the React Native app.
It works fine on Android but on iOS, it encountered CORS error when the React web app tried to call a cross origin API. The error is as follow:
And this is what the code looks like:
if anyone comes here, here is the code that worked for me allowUniversalAccessFromFileURLs= {true} for IOS