How can I connect my ionic app to cpanel node server? - node.js

I'm developing an ionic app which has to be connect with cpanel node.js mysql server. when server runs in cpanel it shows as server is running. but I can't send requests from my app to the server. I'm confused with the server IP and port.
for node js server index.j file I have used port 3000 and host as localhost including mysql db username and pw. I tried to get response by using
url:http://(my cpanel Ip):3000/
var con = mysql.createConnection({
host: "localhost",
user: "bdruser",
password: "ABCD",
database: "users",
multipleStatements: true
});
when I send the requests by using postman it shows as could not get any response

Sorry but you are miles off from getting this right, and I can't give a simple fix:
You must use https for feeds or Android won't play nice.
You cannot connect to a mysql because then the servers password would be in your apps code and be a security risk
You are not connecting to the server in the right way anyway, localhost would only work if you were running that code on the same server as the mysql database.
Node.js is not for using within Ionic apps.
What you need to do is something different but its not simple:
Set up a website on your cpanel server
Set up a webservice on there
Secure the webservice in a way that you can access it from Ionic
Connect the webserver to the mysql database
Write code to expose the data you want through the service

I have fixed my issue. Whats wrong was firewall has blocked my port 3000. After it unblocked now my app is working very well with the cpanel backend server.
Thanks!!

Related

Deploy Create-React-App on a remote Windows Server

I am an inexperienced intern working with a remote Windows Server and React. The Windows Server is running in the company network. I have created a dynamic React website with a NodeJs backend and React Router. I have only ran it on the localhost development server. I want to try to deploy it on the remote Windows Server and give it a custom domain name (Something which can be accessed like servername/myreactapp/).
So far, I have had no success trying to make it work with IIS, even with a web.config file (I get 404 and 500 errors). I am currently making it work by actually running the development server and the nodejs server in the Windows Server, and I access it through the server IP at port 3000.
An improvement would be to be able to access the port through the server name (like servername:3000, instead of the server_ip:3000), but ideally I want to be able to access it like servername/myreactapp/.
Any help would be appreciated. Thank you very much.
The simple solution would be to run your app on port 80 then you will not have to specify the port number.
The best solution would be to set up Nginx on the server and proxy_pass / route to port 3000.
If its running on localhost, which would be port 80, the url would be like http://your_server_name:80, and would be accessible by anyone on the same network, as long as your authentication allows it.

Local server http communication and angular browser rendering

I think I'm doing something completely the wrong way.
I have an Nodejs server running that read in a DB and serve with express some data via http locally (it has to only be accessed locally). It sends the data on localhost on some port (8080 for example). Then I have an angular app on the server that get these datas from an http request on localhost:8080 and display them. The angular app runs locally on localhost:4200.
I was building the entire stuff on my computer and that was working perfectly (I have no problem with CORS). Then I deployed it on a server, and I accessed it via ssh port forwarding. Basically I forward localhost:4200 on the server via ssh on my local computer on localhost:8090.
And my problem is that, when loading and executing the angular app in my browser via port redirection, it's doing a get request to localhost:8080. So it's trying to communicate with the localhost it's running on, which is the client itself.
If you understood my spaghetti situation, there is actually a dirty solution : redirect localhost:8080 on the server to localhost:8080 on the client.
Is there any way to do the get request server side and not in the client's browser so that localhost correspond to the server? Is there a better way to do what I'm trying to do?
I can sum up by : How can you access another local service on localhost on the server with angular app since it executes in the client browser and localhost will refer to client localhost.
Try to use any web server (such as nginx or apache2 or etc.) in your server and make use of proxy and reverse proxy with your node application, it will work
angular2-router-and-express-integration

How to connect node app to node api with Nginx

I built a Node app using this tutorial. Then I built a Node API using this tutorial. The app uses the app on port 4000 to connect to the API which then connects to a mongodb to store the info on the server.
This setup works great on my local machine, but I'm trying to deploy it on a digital ocean droplet. I have Nginx setup to listen to port 8080 for the main app. I'm able to navigate to the app. But when I try to register a user and submit the data to the API I get the following error in my browser OPTIONS http://localhost:4000/users/register net::ERR_CONNECTION_REFUSED.
I suspect I have to specify something in the Nginx config files. Or would it be a ufw issue? Any help would be much appreciated.
The error is very clear. The application try to fetch on localhost:4000, so you expect any visitor of your web app to have the API launched on their own computer.
Change your code to point to the correct host and port of you server.
Then, as you guess it, you will have to create a little Nginx configuration to tell him what to proxy to the APP and what to proxy to the API.

Connect to MongoDB database using mongoose behind a proxy

I am using mongoose to connect to my database in mongolab in my server.js file :
mongoose.connect('mongodb://MyUsername:MyPassword#ds089702.mongolab.com:89702/todo');
When i launch my server with node server.js command, i see this error in my terminal
failed to connect to [ds089702.mongolab.com:89702]
I am very sure that is just a corporate proxy problem, so I'm wondering how can I connect to my database over the corporate proxy using mongoose ?
Thank you!
I had the same problem and figured out a solution that worked for me.
Example mongodb URI:
mongodb://:#ds123456.mlab.com:37409/dbName
Use a proxy client (e.g. Proxifier).
Create a HTTPS proxy through port 8080 using your corporate proxy as the address.
Create a rule for mlab using your URI's port as the target port, which uses the HTTPS proxy you created above as its action.
Prioritize your mlab rule high in the rules list.

Allowing external access to node.js application while hosting through XAMPP

So I have the following URL that leads external users to my port-forwarded XAMPP website.
http://ip_to_my_computer:433
However, my node server is on port 466. How do I connect to it? I can't do
var client = io.connect('http://ip_to_my_computer:433:466');
Thanks!
It looks to me like you're trying to initiate a client request from your XAMPP hosted server (like a .php or .js script) to your Node.js instance?
Simply:
var client = io.connect('http://ip_to_my_computer:node_server_port');
And in your case, you claim your Node server is running on port 466.
I'd bet though that your OS will block a port that low - try changing your Node server to listen on a port between 8000 - 9000.

Resources