GET request permissions error with React native expo and express server - react-native

I'm calling a GET request with axios in my React Native EXPO app but getting a NETWORK ERROR consoled in my terminal. I can make request to my Express server from my web browser but not my RN app.
I added this to my app.json file as I do to my React apps, but I'm not sure what the issue is. Any help is much appreciated. Thanks guys.
{
"expo": {
...
},
"proxy": "https://localhost:7000"
}

I figured it out! So I tried using axios.get("/") and axios.get("http://locahost:{PORT}/") and still had no luck but using axios.get("http://192.168.x.x:{PORT}/") worked. Looks like I need to use my local host IP adress to make API calls. I also removed the proxy script in my app.json

Related

React native project to use heroku express url

I have heroku backend express server project.I have react native project. I am trying to use heroku express url in my fetch in react native.. but I am getting network request failed.
I have two questions.
1.Why is that url not working in react native fetch, but opening in heroku.
Like react, can we put static files in build and try to serve that build in express app.use(express.static("client/build"));
Thanks a lot in advance.

React Native expo-facebook: Error ‘Given URL is not allowed by the Application Configuration.’

I’m trying to get Facebook Login working using the expo-facebook package (I'm using the Managed Workflow)
I created my application in the Facebook Developer Console and copied the “App ID”.
This is the code I'm using inside my React Native Expo app:
async facebookLogin() {
await Facebook.initializeAsync('26327628297297')
const response = await Facebook.logInWithReadPermissionsAsync({ permissions: ['public_profile']})
console.log(response)
}
My understanding is that while using the Expo Client App there is no need to do any extra configuration because it will be using Expo’s Facebook App ID for all API calls.
The problem is that after logging in I get this error message:
Given URL is not allowed by the Application configuration: One or more of the given URLs is not allowed by the App’s settings. To use this URL you must add a valid native platform in your App’s settings.
I also tried added “facebookScheme” to my app.json but that didnt seem to help:
"facebookScheme": "fb26327628297297",
Thanks for your time!
Actually you just have to add platform in your app settings
So here are the steps
Open https://developers.facebook.com and select your app
Settings > Basic > Add Platform
use host.expo.Exponent as bundle id
3.Now select iOS from the window and add your Bundle ID and rest of the information and click on Save changes
and that's it.
Hope it helps you .. All the best

Network Request Failed when trying to upload formData using Expo

I'm trying to upload a formData using fetch API. I'm using Expo and my server is a feathersjs, with ngrok.
All other requests are working great, just those with formData files.
Trying with Postman also works perfectly.
I've noticed that this happened after I run yarn upgrade.
It seems to be an issue with Flippers on React Native 0.62.
So when I make the request it returns me the Network Request Error, but on the server side, it continues normally. But the problem is that I don't know when it finished on my server, so my Expo app cannot work accordingly.
If you guys don't know how to fix it, do you have any idea of a workaround that I can implement? As I said, on my server it still works perfeclty, but as my Expo App already returned an error, I can't work properly on my frontend. Should I make another request to look for the resolve of the file uploading?

Impossible to use proxy

I'm trying to use proxy with my react-native app (build with CRNA and Expo).
So in my package.json file I put : "proxy": "192.168.1.27:8080" and then make simple get request with fetch with the/users` path and react call me network error (he don't see the proxy param, just /users when I'm debugging).
The fetch request work well if I put the full url.
In react (for website) I do the same thing and that's work to.
Thank's for your help.
In Reactjs proxies are mainly used to avoid cors issues. Since React Native connects to iOS & Android natively, there is no browser issue so you don't need a proxy.
The approach I use is to call http:127.0.0.1:nnnn/api/route (not localhost) in the React Native app when testing the backend, and the deployed url in production. So you can deploy your server separately and reach it directly in the app.

Getting Socket.io to work in Android Webview

I am trying to use socket.io inside an Android Webview, inside a native Android app. The Android activity file has been updated with;
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl("file:///android_asset/www/public/index.html");
My problem is loading the socket.io.js libraries from the index.html:
<script src="http://mydomain:port/socket.io/socket.io.js"></script>
The error I get during the rendering of the webview is:
XMLHttpRequest cannot load http://mydomain:port/socket.io... Origin null is not allowed by Access-Control-Allow-Origin.
I am using a node.js/express server to try and serve the libraries and thought I had configured this to accept cross-origin-resource-sharing (CORS) by setting
res.header('Access-Control-Allow-Origin', "*");
Now I am completely stuck! Can anybody recommend a way forward to get socket.io working in this configuration?
Cheers,
Kirbs
why not run service socket.io at activity, try my answer at this
singleton service socket.io
I using socket-io.java client library from github
Gottox