Axios request getting network error on Expo - node.js

I have an expo mobile application running on an Android emulator and I'm trying to make a request to a local Node.js API. The request is through HTTPS protocol so I created self-signed certificates to be able to try the application.
Every time I try to make a request to the API Axios throws a Network error.
Network Error
Stack trace:
http://192.168.1.35:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:168381:25 in createError
http://192.168.1.35:19001/node_modules%5Cexpo%5CAppEntry.bundle? platform=ios&dev=true&hot=false&minify=false:168285:26 in handleError
node_modules\event-target-shim\dist\event-target-shim.js:818:20 in EventTarget.prototype.dispatchEvent
node_modules\react-native\Libraries\Network\XMLHttpRequest.js:600:10 in setReadyState
node_modules\react-native\Libraries\Network\XMLHttpRequest.js:395:6 in __didCompleteResponse
node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:189:10 in emit
node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in __callFunction
node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 in __guard$argument_0
node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 in
callFunctionReturnFlushedQueue
[native code]:null in callFunctionReturnFlushedQueue
...
I tried the following:
Configuring the API IP on the mobile application as 10.0.2.2 as suggested in the GitHub issue and didn't work.
Testing the application without HTTPS, which works perfectly fine.
Testing my application on an iOS device, but it has the same behaviour as the Android emulator, it works with HTTP but it does not with HTTPS.
Accessing the HTTPS URL from the emulator's browser, which also works.
My HTTPS server is configured as follows:
const httpsServer = https.createServer(Certificate.getCertificate(), app);
httpsServer.listen(Environment.PORT, "0.0.0.0");
Logger.logInfo(`Listening on port ${Environment.PORT} under HTTPS protocol.`);
In order to create the self-signed certificates, I followed the Heroku guide

Related

Electron.js Connection Problem with openvidu

I have an project with vue electron builder and node.js.
While i sending request from Openvidu server, i have an error.
This error is;
webSocketWithReconnection.js?714c:61 WebSocket connection to 'wss://localhost:4443/openvidu' failed: Error in connection establishment: net::ERR_CERT_AUTHORITY_INVALID
How can i fix.?
You must configure your Electron app to accept self-signed SSL certificates if you are going to use a local development OpenVidu deployment.
In your Electron app add: https://github.com/OpenVidu/openvidu-tutorials/blob/f39d38fe14ea48dcb17c4fff4c39cc198f36ab8a/openvidu-electron/src/main.js#L69-L74

CORS doesn't allow connection to API even though it is set to all

I've ran into a problem where when I host a server with webpack on my local network (Webpack default I suppose), on the laptop that the front-end server is being run, everything works when connecting through localhost or the IPv4. When trying to connect to the website through IPv4 on my desktop I get this error.
createError.js:16 Uncaught (in promise) Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:84)
My CORS:
const cors = require('cors');
app.use(cors());
I set CORS before any APIs are created. Also my front-end is being ran my webpack since I'm using CRA. Webpack running front-end on network:
Try Using below code :
app.UseCors(builder =>builder.WithOrigins("http://example.com").AllowAnyHeader());
replace http://example.com with the request origin domain address .
try adding app.use(cors({origin: 'you localhost eg https'}))
this will allow only your localhost to access in your server
Fixed it. Hosted my Node JS server on my network IP instead of my localhost aswell as configured all front-end requests to the network IP. Works like a charm.
app.listen(9999, '192.168.1.226', () => {
console.log(
'Arclight back-end is online.\n',
'',
);
});

My Ionic app can't access my local Node server from Android emulator

I'm trying to run for the first time my React/Ionic app on an Android Emulator using Capacitor. The app should connect to my local Node server using Axios.
While my app started successfully on the emulator, all server requests failed with Msg: Error: Network Error
Here's the steps that I did:
I configured Axios to connect to http://10.0.2.2:3001 instead of localhost, but the requests still fail
I opened the url http://10.0.2.2:3001/api in the Android Emulator Chrome browser, and it succeeded in connecting to my server and returning a response
I tried adding to my capacitor.config.json file the following conf, but my app still fails
"server": {
"allowNavigation": ["10.0.2.2"]
}
Would you have other advices I should try to make my app connect to my local server? Thank you
After searching, I found the solution in another SO question :
The problem comes from the fact the my app uses http instead of https requests which Android forbids by default, starting with API level 28.
To allow http requests, I added android:usesCleartextTraffic="true" to my app's AndroidManifest.xml
Reference: https://developer.android.com/guide/topics/manifest/application-element#usesCleartextTraffic
if you use instances on cloud, modify host file, on linux the rute is : /etc/hosts
add this line:
localhost < ip-public-your-instance >

socket.io-client-cpp does not connect to node app on Heroku via https

socket.io-client.cpp does not connect to node app on Heroku while Node JS socket.io-client does without any problem. Error is:
[2018-12-11 19:32:43] [connect] Successful connection
[2018-12-11 19:32:43] [error] handle_read_http_response error: websocketpp.transport:7 (End of File)
[2018-12-11 19:32:43] [info] Error getting remote endpoint: system:107
Changed URL from https to http://myapp.heroku.com - works now. Is it possible to connect via https as well? JS socket.io-client connects via secure connection without any problem.
Have built socket.io-client-cpp app with SIO_TLS in DEFINES (compiler flag: -DSIO_TLS) - connects via https fine now! This enables TLS support as mentioned here:
https://github.com/socketio/socket.io-client-cpp/pull/137

mern project deployment on live ssl

I want to deploy a mern project on ssl. Currently it is running on server with ip address but when I deploy it on ssl it is not running. It is working fine on http.
I have change on node modules transport-node and make it http to https.
1-I am using nginx as proxy server
When I deploy on ssl it give error:-
1-emitter.js?8a6f:50 OPTIONS https://privateIp:port/ net::ERR_SSL_PROTOCOL_ERROR
2-websocket.js?0f24:6 WebSocket connection to 'ws://privateip/sockjs-node/831/bocznd0p/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400
3- your request is http,while it is require https.(handshake problem)

Resources