How to make API calls to local server using self signed certificate? - javascript

I have a api (node.js) running on https://localhost:3002 which is using a self signed cert I generated using this
https://trendoceans.com/how-to-create-https-server-in-node-js/
And I have a web app running from vite tooling. Also in https. When I make a all from the web app to the api, I get
GET https://localhost:3002/create net::ERR_CERT_AUTHORITY_INVALID
How can I get this to work?

Related

How to handle backend API request for create-react-app bootstrapped app which is build and ran using "serve-s build" on AWS ec2?

I have create-react-app bootstrapped application which I build and then serve it to the static server using serve-s build. The React app is running on http://locahost:3000.
This app talks to my backend REST API(using java) which is running on http://locahost:8080.
Inside my React application, I have set axios.default.baseURL=http://localhost:8085/api.
Everything is fine on the localhost on my system. The React app talks to http://localhost:8085/api/xyz for CRUD operations and everything works great.
Now I have to deploy the project on AWS EC2 instance. The MySQL and REST API got deployed and rest API there is running on same instance on the port 8085 as http://locahost:8085. I have Apache server configured which sends the hostname(www.myxyzwebsite.com) to the http://locahost:3000 on the server. Everything is fine till now. The home page is visible on the browser.
Now, when the React app tries to communicate to the REST API from the browser, it is sending the request to the http://locahost:8085. Obviously, now the browser looks for some service running on port 8085 on my system and it couldn't find. Ideally, the request should go to the server with my hostname(www.myxyzwebsite.com/api/users/puspen). How to make this REST API call looks like an actual call like www.myxyzwebsite.com/users/pusp?
NOTE: Please note that this is not a server-side-rendered application.

How can I execute functions in a node.js file hosted by Heroku from a file hosted in a different environment?

I currently use host winds to host a html/css/js files. I need to use Node for a new project aspect, and host winds says id have to use a virtual private server. so I figured ill use Heroku, since I have experience deploying to that environment already.
the heroku application has to execute a stripe operation:
(dummy data)
const stripe = require('stripe')('sk_test_NOFBwvYmIyZln2c64bv84A');
stripe.oauth.token({
grant_type: 'authorization_code',
code: 'ac_123456789',
}).then(function(response) {
// asynchronously called
var connected_account_id = response.stripe_user_id;
});
followed by a firebase firestore write operation
How can I connect to the heroku environment from a file hosted on Hostwinds? Is it as simple as creating an express server in the node.js heroku deployment, and calling a fetch POST/GET to an express endpoint from the web page thats hosted by host winds
Is it as simple as creating an express server in the node.js heroku deployment, and calling a fetch POST/GET to an express endpoint from the web page thats hosted by host winds
Exactly, call one of the routes in your app on heroku servers and then run your function from there.

Fetch JSON from same Server (localhost) but different Virtual Host

I'm having quite a basic issue I suppose. I've set up CraftCMS to be reachable via Apache Virtual Host http://craftapi and am using Element API with routes such as http://craftapi/projects?page=1 etc.
On a separate Virtual Host http://mysite I've set up a react-static install which should fetch the JSON using Axios from http://craftapi/projects?page=1 but it throws after Importing routes from directory... with:
Error: socket hang up
Am I not allowed to fetch from a different domain? Even if it is hosted on the same server?
Thanks

Creating a react-native app for IOS and I have created a Microsoft SQL server, how to connect these two?

I have an app built on react native and I want to connect to a database that i have made on the Microsoft SQL server. I have searched online and there are things like myssql but I still get errors with that. I followed this tutorial nodejs from the official Microsoft website, and it works with the nodejs and I use node to run it, but how can i use this in my react native project?
You can use AXIOS to make requests to your NodeJS Server
In Android you can access your localhost by the IP 10.0.2.2 (default proxy configured in your Android Virtual Device).
In iOS you can just use localhost
Remember to add the port assigned your NodeJS Server and the
protocol http
Example URL for Android: http://10.0.2.2:3000
You need to write back-end service code.I suggest you to use Asp.Net Web API .You can use Entity Framework.
Also you can use PHP,Java or Python...

Firebase can't authenticate after building electron app

I have a problem with Firebase, React and Electron. When I use my app in dev, I use the localhost to load with react-scripts start , so it's loading in http://localhost:3000. I use this url to load my app with Electron.
BUT when I am trying to go in production, I use the electron-builder. I build my app with react-script build, it's create the build folder, and for the electron app, I change the loading url for file://${path.join(__dirname, "../build/index.html" I use build -c.extraMetadata.main=build/electron.js. It's now loading perfectly. BUT When I try to authenticate nothing happen and in the console, it says :
code : auth/operation-is-not-supported-in-this-environnement
message : This operation is not supported in the environnement this is running on. "location.protocol" must be http, https or chrome extension and web storage must be enable
How I can resolve this ?
My hypothesis it's because I don't write the url of my app in Authorized domains in Firebase Sign in method, but there is no url for my app, it's local. Does I need to load a server to employ Firebase ?
I see a similar post but without answer
I think it's because the SDK thinks it's running from a Node.js server environment. Currently, OAuth sign in with popup or redirect is not supported in Electronjs. You would need to get an OAuth credential from an electron compatible library and use the signInWithCredential API.
Firebase is looking into supporting signInWithPopup/Redirect in this environment.

Categories