Ubuntu Node js With Socket io Not allowing client to connect - node.js

I'm trying to get the socket.io working in Ubuntu using Nodejs.
Tried to disable the firewall, open ports 3000,4000.
I'm using PM2.
Deployed In DigitalOcean
Now in my Angular client App I get this error
Also I have core errors setup in my node js
client:1 Access to XMLHttpRequest at 'mydomain.com/socket.io/?EIO=3&transport=polling&t=N4_SuJm'
'Access-Control-Allow-Origin' header is present on the requested resource.
Although I did publish the same code in AWS ElasticBeanstalk and it worked just fine so nothing wrong with the code
UPDATE
I managed to solve the issue

UPDATE
I managed to solve the issue
For future reference
the problem was that the socketio client removes the path from the url
that is given when connecting exampledomin.com/api is the correct path
for socketio in node js but the socket io client removes the /api and
points it to /socketio so i added a Location in the nginx config to
point to the server hope this will help someone down the road

Related

How to connect my React app to a backend with which is different origin

Hello Experts
My problem is I am developing a react js application with some Axios call, I am connecting my serverside backend (which is an indifferent location like a real IP address) with writing a proxy in package.json which is working on my pc is fine,
But when I am going to deploy my application on AWS in production mode, unfortunately, the backend is not connecting (Maybe proxy is not working as I learn by google search ), in this situation what should I do to connect my react js app with my backend
please help me if you can thanx in advanced
Usually browsers block cross-origin request by default.
Please check cors npm package to whitelist/allow requests from your react app to backend server.
link: https://www.npmjs.com/package/cors
Hope this helps. :)

Proxy module doesn't work when serving nuxt app statically

So, Iv'e been trying to setup a small example of a server with 2 factor authentication features. I'm using nuxt as the frontend and flask as the backend.
While developing locally (using npm run dev) I was able to get the chain of communication to work:
The webpage sends a request to server/<some_request>/<some_param>
The proxy module redirects it to http://localhost:5000/<some_request>/<some_param>
The request is sent by the axios module
flask receives the request, processes it and answers.
When trying to deploy this application to a dreamhost server, I used npm run build and npm run generate to serve the website statically. I was able to receive my webpage when browsing.
But when trying to login, the chain described above broke, and requests to server/<some_request>/<some_param> were answered with 404. In the server's command line I saw that flask didn't receive any request, so I assume that this is some issue with the proxy module.
I'm not really sure how to debug this problem, so any help or ideas will be appreciated.
Okay, so I got everything working, and here are my conclusions:
The proxy module, makes the redirection in the client side, meaning that I would be trying to access my own machine when redirecting to localhost:5000, rather than to the server.
The proxy module can't be used when using npm run generate (there's a warning that says it's disabled).
Since I wanted to redirect to flask from the client side (browser), I couldn't just run it as is. I had to register another subdomain and use Passenger to deploy my app (A guide to enabling passenger, getting started with python in passenger and A great guide to deploying flask over passenger).

client not connecting to node js server on AWS with WSS/WS protocols

I created a small server using socket.io and node js and deployed in heroku earlier. I was easily able to have client connected to server with wss/ws protocol but when I deployed my app too AWS, Clients are not connecting. I debugged the application in client side but Its just not connecting to server. Did I miss something? are there extra steps needs to followed to make it work?
Thanks.
Answering my own question, I had to add .ebextensions folder with a config in my project root directory. You can look at the following tutorial to make it work https://nikhilmopidevi.github.io/2017/10/18/WebSockets-with-AWS-Elastic-Beanstalk/

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.

Laravel Forge - Node.js Websocket Timeout

I have a simple socket.io node server hosted on my laravel forge/digital ocean server. Everything is working find on my local machine using homestead, however I get the following error on production:
http://[IP]:[PORT]/socket.io/?EIO=3&transport=polling&t=LCPeh0O net::ERR_CONNECTION_TIMED_OUT
On the server I can see that the node server.js file is receiving messages from Laravel but the client can't connect for whatever reason.
Is this something to do with the setup of Nginx? The configuration is the default forge one.
Thanks for any help, much appreciated.
For anyone facing this problem, the fix is to expose ports for SocketIO (6001) and Redis (6379). Go to network tab in forge and set new firewall rules (or do it manually if you are not using forge). After that everything works perfectly.

Resources