React Native Axios allow self signed ssl certificate - javascript

I'm writing an app in React Native, and I need to make API requests. The server for that is running on a server with a self-signed SSL certificate, so I need Axios and React Native to make the request and accept the response using a self-signed certificate.
I can't get a certificate from an official certificate authority.
I have already tried using https.Agent, however this doesn't seem
to be possible when using React Native (The https module is part of
the node standard library, which is not included in React Native), so
this is also not a valid solution.
I would prefer to continue using Axios, however I would consider
switching libraries if there are any with similar functionality (I've
already tried a few, none provided functionality to allow self-signed
certs).
Here is some example code from my project (url is the IP of the server):
import axios from 'axios';
const instance = axios.create({ });
instance.get(url)
.then(res => {
this.setState({dataSource: res.data});
})
Btw, when I'm using ngrok everything works fine, so the self-signed certificate is definitely the only problem.

I solved this problem today! I too have a react native app, and i use apisauce, an awesome lib that uses axios under the hood.
My API runs on a LAMP stack locally, and I have a fake development domain in /etc/hosts, and Apache is configured with a self signed certificate.
Instead of disabling the SSL verification, trust your certificate!
The instructions will differ on Android, but for iOS I did the following.
Send the selfsigned.crt to my iPhone via Airdrop
Install the profile in the Settings app
Download and launch Proxyman on my dev machine https://proxyman.io/
Set Proxy in Wifi settings on the iPhone (dev machine IP port 9090)
Open Safari and goto proxy.man/ssl, download the certificate
Install the profile in the Settings app
Enable full trust for both certificates in Settings > General > About > Certificate Trust Settings
Now you should be able to access https://your-dev-domain.whatever without any problems, and apisauce/axios will no longer return Network Error 😎
Just remember to go back into your wifi settings and turn the proxy off again when you are finished developing!

Related

Webpack log errors "net::ERR_SSL_PROTOCOL_ERROR" by calling sockjs-node/info

on front I use react on back .net core 3.1
on client I use webpack that is runned on localhost:8080
in Startup.cs I use proxyToSpa
applicationBuilder.UseSpa(spa =>
{
spa.UseProxyToSpaDevelopmentServer("http://localhost:8080/");
});
on HTTP works as expected without any errors but on HTTPS I saw a lot of console errors and failed requests in Network there is failed requests for (sockjs-node/info?t=...) with error net::ERR_SSL_PROTOCOL_ERROR
Is there any options to configure webpack or .net core project to avoid these error logs on HTTPS?
This might be the issue, it worked for me
https://howchoo.com/chrome/stop-chrome-from-automatically-redirecting-https
If you ever visited the https version of a website (whether it resolved or not), Google Chrome might repeatedly send you to that version
https://webpack.js.org/configuration/dev-server/#devserverdisablehostcheck
using cli
webpack-dev-server --disable-host-check
or in webpack config
devServer: {
disableHostCheck: true
}
My main site was using https (reverse proxy to development server), so definining public: http://... didn't help for my development server, because the browser forced https (as the main site was https to).
What helped me was using https in the devServer too:
https://stackoverflow.com/a/29772748/3279070
It was important that devServer HTTPS was signed with a good certificate like the main site was (the reverse proxy) and uses a hostname (public property) signed by the cert. So for example typical scenario is using the same certificate files and the same hostname (public: 'https://hostname:8081') as the main site

export my localhost server ( node js ) online with a web server like apache

I just made a simple chat-service with Node JS and I want to publish It " Online " ; at the time I used Ngrok and Localtunnel , but they are very limited , therefore I saw Apache web Server but I have not found tutorial on how to use it.
Thanks and hope you can help me.
Ngrok and Localtunnel are services which let you open a connection from inside your network to an external server which then forwards traffic back down the tunnel so clients on the Internet can make requests to your service running inside your LAN.
Apache is HTTP server software. It is nothing like Ngrok and Localtunnel.
While you can set up a reverse proxy using it, for that to use useful in this use case you would have to install it in your router … and most routers don't let you install software on them.
You could possibly run it on a computer inside your LAN and then configure port forwarding on the router … but if you are going to do that then you might as well forget about Apache HTTPD and just forward traffic directly to the service you've written using Node.js.
There are security risks and bandwidth considerations to take into account when running services from your LAN. It's almost always a better idea to just invest in a proper hosting service like Amazon AWS, DigitalOcean Droplets, or Heroku.
By "online" I suppose you mean to host it globally. For that my friend you will be in need of a server (preferably a cloude server) and a static IP address. Both of these are provided by a lot of providers like aws, digitalocean etc as a platform as a service, which we can leverage. So pls do the following:
Register for a cloud service (aws, digitalocean, gcp etc.).
Create a server instance of an operating system of your choice (my pref would be a linux instance).
Attach a public static ip to the server.
Log into the server. (SSH is the most secure way and most providers provide this to log into your server).
Install dependencies (in your case NodeJS etc).
Make sure that the port in which the app is hosted is open publicly. Most providers provide a dashboard in which you can configure port settings.
Use Apache or Nginx for configuring a reverse proxy (this is just for keeping your environment secure)

Ember - Force https with heroku

I've made a ember app deployed on heroku. Heroku provides me an ssl certificat so https is working on my website.
I want to force visitors to uses https. I've found some answer telling to do-it in a client side, but since the client can modify JS he will be able to pass-by the force https.
I'm thinking about doing it in a beforeModel of the ember app.
What's the best approach ?
Many thanks
So guys,
I was able to force HTTPS by adding a static.json in my root folder of the app.
And in this static.json just add
{
"https_only": true
}
commit, push to heroku and that's it !

WebSocket client can't connect to cloud server through corporate proxy except for web browsers! (ETIMEDOUT)

I'm trying to connect a WebSocket client (corporate Node.JS server) to a Cloud server, but it times out (connect ETIMEDOUT error).
I'm not sure which needs configuration... Linux, Node.JS or the WebSocket Client?
I've already configured the proxy for Linux (export proxy/https_proxy), and for Node.JS (npm config set proxy/https_proxy) but the problem persists!
I'm using the ws library found in https://npmjs.com and implemented it without any sort of options except setting port.
Any advice?
EDIT: Works fine in the web browser, by the way.
node does not automatically use any form of configuration for making HTTP requests through proxies -- ie, node does not read the PROXY or HTTPS_PROXY environment variables. npm config set proxy only affects npm itself.
In other words, node programs always try to access servers directly. It appears your network requires HTTP requests to go through a proxy, and direct connections are being silently dropped.
If you want your program to make HTTP requests through proxies, you must do so manually. The http-proxy-agent module can help you do this.

Consume Rest API on same ip but different port

Let's suppose a backend application, which exposes some Rest API, running on a Jetty webserver at address 192.168.1.10:8889.
I would like to have a frontend application (html/javascript only, on a apache2 webserver) running at the same IP but on a different port (e.g. 8000), which should consume the API exposed by the backend application.
How can i get this architecture working without get into "No 'Access-Control-Allow-Origin'" error?
I think that you should install a nginx proxy.
configure it as a reverse proxy you can see documentation here :
https://www.nginx.com/resources/admin-guide/reverse-proxy/
You can search on google for more specific documentation on what you want to do.

Categories

Resources