net::ERR_CONNECTION_REFUSED when moving app from local machine to remote server - node.js

Had a look around at some other threads and there doesn't seem to be someone with this exact problem.
The problem is that I have made a webapp that works fine when hosting it locally. On the app there is a button that causes a request to be sent to my server and it performs as expected on localhost:3000 but when I host it remotely on a linux box purchased from digital ocean the site loads but the when the button is pressed I see
net::ERR_CONNECTION_REFUSED
in the console.
I'm not sure how useful it would be to post code so I will leave that out unless requested. I'm hoping this is due to some server configuration issue?
Further info:
This is a node application on a server running ubuntu. To run the application I use and keep it running I use PM2.
Thanks in advance.

Related

Heroku This site can’t be reached (DNS_PROBE_FINISHED_NXDOMAIN)

Some of my personal apps and my professional apps on Heroku are not accessible.
They don't have a custom domain linked, so I access them via http://.herokuapp.com
Most of the time, they work great, but often I receive following response from my browser
This site can’t be reached
<myapp>.herokuapp.com’s server IP address could not be found.
DNS_PROBE_FINISHED_NXDOMAIN
The app is up and running. It does not crash (as I haven't made any changes to it in a while).
I have tried restarting all dynos, to which the log says that the app is up and running and the db is connected.
Heroku is also not reporting any of their services to being down either.
How can I resolve this issue?
I have read a similar question, but the only result coming from it was that Heroku was temporarily down. So please don't link that one again.
Update
Without any of my interference, the application can be reached again on Heroku. How is this possible if Heroku says that there were no problems with their app platforms?
And more important: is there a way to defend against this?

CrushFTP on Azure VM giving "405 Method Not Allowed error" for POST method

We had CrushFTP installed on an Azure 2012 VM that recently died, so to speak. We wound up spinning up a new VM and reattaching the original data disk to the new VM.
After configuring IIS for the web portal part of CrushFTP, and cleaning up some script errors on the landing page, which is now on a 2016 VM, we get an HTTP 405 error when trying to log in to CrushFTP.
I checked to make sure the VM accepts POST requests - it does. The confusing thing is when I check the browser console, it's saying the server is NOT accepting POSTS, and this is happening both on our company network and from outside the network. I can see from our work network it's an issue with our proxy server, but from my mobile device outside of the network, I see the exact same rejected methods.
Any ideas? I don't have a whole lot of code to share since CrushFTP is a black box.
EDIT: I think the IIS setup was a red herring. I was going off some notes from a former co-worker who set this up, but I don't believe she set it up in IIS.
From what I'm reading, the CrushFTP HTTP server needs to be exposed as a public app through port forwarding in the VM. Whenever I run Crush locally on the VM, everything works fine. But since I set it up in IIS it hasn't worked.
I figured it out. I had to add an "Allow" entry of POST in IIS.

Getting over a 426 upgrade required

I've been working on a web app (front Angular, back Node/Express/Mongo) for a few months now.
I run Angular on localhost:4200 and Node on localhost:3000
Some people in our team are running the backend in a VM that runs on their computers.
So that the app works in both cases we've edited the windows hosts file to make the app point to the correct place (either the VM or the back on the local machine)
127.0.0.1 mysite
Developers using the VM changed 127.0.0.1 with their VM's IP.
Everything worked smoothly.
A few days ago, our company installed bitlocker on every PC and I believe it caused our setup to break for everyone not using the VM (which is not subject to bitlocker)
People working on localhost started receiving from the front app:
OPTIONS http://mysite:3000/auth/login 426 (Upgrade
Required)
The requests are not even hitting the Node server. Looks like they're redirected to a websocket server?
If I change the requests to target localhost:3000 the app works again but we lose the setup for people working on the VM. (thus committing code becomes annoying if we need to change the base url each time)
I could make an environment for each case but it's not clean and I'd like to know why it suddenly broke.
Try changing the port from 3000 to something else.
I just ran into this issue when a coworker tried running an express app we've been building on a Windows machine for the first time, as opposed to an EC2 instance. I've been using a Mac during development.
The issue seemed to be that 0.0.0.0:3000 was already mapped on company Windows machines. If you run netstat -an in a command prompt you may see it in use already.
hello mate this usually happens due to protocol mismatch between the PC and server.TLS 1.0 and 1.1 were permanently deprecated on June 4 2018. I suspect you’re using something that still uses and old version of TLS.

ReactJS: How to deploy on local server

I have a web app developed with a NodeJS + Express + GraphQL + MongoDB back-end and a ReactJS + Apollo front-end. I would like to deploy this application locally. Is that even possible?
I have come across dozens of "how to deploy to Heroku," "how to deploy to Digital Ocean", "how to deploy to Github", etc. But none that explains how to deploy locally.
Right now, I run: nodemon server for the back-end, and npm start for the front-end. I see the application running on http://localhost:3000/ (I use cors to connect the front end with the server running on port 3001).
I would like to just go to http://localhost:3000/ and see the app without having to execute the commands npm start and nodemon server. Is this possible? If so, how do I do that?
To my knowledge, our local server is not a WAMP server (our OS is Windows though). The IT department told me that it is a
[...] plain, regular old server. The address is localhost running on
port 3000. You can open up another port on 3001 if you need it. Just
drop your stuff on the C: drive and you should be good to go. I've
never heard of Node or React so I can't help if you have questions.
Any ideas? Many thanks in advance for your help!
UPDATE
There seems to be a bit of confusion surrounding what I am looking for. I am trying to deploy this locally.
Let's say, on your local computer (your laptop at home) you go to localhost:3000 on your favorite browser. Unless you are serving something to localhost in that moment nothing is going to show up, it will say "refused to connect" or something. What I want is to be able to open any machine on the network whenever I go to localhost:3000 and my react site appears and functions...does that make more sense?
I don't want this is development mode. I want a build of this project on localhost...I'm starting to think this isn't possible.
As i understood, you want to deploy it on a local server, not locally on your developing device.
I thought about doing that...but I'm not so sure IT will be okay with it always running... :(
How can you use a server if its not running? Just like WAMP (which runs apache), or whatever you got rolling there, it must be running. So, just make it a background process like slawomir suggested.
PS I dont think you understand node server properly though.
Read this to understand why node server needs reloading. After that you need to understand that no hot reload tool is perfect, and you gonna need to restart your server from time to time.
PPS I dont know what this means
[...] plain, regular old server. The address is localhost running on port 3000.
if there is a server running on 3000, youll need to change port for your server to smth else (most common is 9000)
To solve the problem you can create a startup script, which executes npm start and nodemon server. Then make sure to keep it hidden, so that your server will be always running. Keep in mind though, that any errors thrown will stop your server and unless you configure it, the server won't reload by itself.
I would try following:
build your app with the production environment variables set
get all files from dist folder and deploy them in your server
now access your app using localhost/
Maybe what you are looking for is something like ngrok which creates a socks tunnel to your localhost, effectivelly deploying from localhost, as I understand it, allowing you to access your localhost through a url like ldiuhv093.ngrok.io, or even a custom subdomain if you pay for a subscription fee.
If I have this wrong, someone please tell me!
To solve the problem first of need to create a batch file with .bat or .cmd extension and under that file add the following 2 command
nodemon server
npm start
Then follows the following steps to add it as a startup script for windows OS.
Create a shortcut to the batch file.
Once the shortcut has been created, right-click the file and select
Cut.
Press the Start button and type Run and press enter.
In the Run window, type shell:startup to open the Startup folder.
Once the Startup folder has been opened, click the Home tab at the
top of the folder and select Paste to paste the shortcut into the
folder.
Above steps are for example to create a batch file and add it as a startup script for Windows 8 and 10 users.
For better clarity or reference follows the following link.reference-link
There's no option to reload the server while keeping it running. You could, technically, have your 'main' file monitor another file for changes. This would be the file where you actually keep your sever program. Then, on changes, you discard your current logic and start executing that. That said, doing it that way would be very fragile and a very round-about way to do it. It also wouldn't fix your front-end for which you'd need a similar solution.
Instead, you could hook into your favorite editor's save event, and run those two console commands, so that every time you save, the server is automatically brought up. (Make sure to also clean up existing servers)
Run on Save for VSCode
save-commands for Atom
I know this post has been two years. But, I think the solution to your second desired outcome is to use concurrency. https://www.npmjs.com/package/concurrently.
This will allow you to do one NPM START to start two all three processes.
and to your first question, I think the solution is to add Electron to your app so you can package it to an executable application. When you start the app, your express server will start running in the background.
Most people probably don't understand why there is a need for this. Running on local server (computer) allows access to local file system and can even run SQL queries inside the proxy which would require IT involvement if hosted on outside server.
From what I have understand, that you want to deploy your app on local server that means you want to deploy it on the network that you are connected to.
Check ip from the command prompt
To deploy it locally,
Run: HOST=ip npm run start
It will get deploy on your local server. And everyone connected to the server can access the url
If this worked for you, kindly upvote
You need to do npm start There may be other ways of starting it but, all will result in the same. You can read this article on Freecodecamp on deploying on DigitalOcean. You can manipulate it to your localhost. Shouldn't be too different.FCC Tut on Deploying

wkhtmltopdf as node module fails when run as windows service

I am running a node app that uses the wkhtmltopdf module (https://www.npmjs.com/package/wkhtmltopdf) and node routing to return a pdf of a page when the user navigates to a /pdf path. Everything works fine when the app is run on in the servers console, but when the app runs as a Windows service, the pdf call fails. I get the browser crash screen with the message that the site refused to connect. The rest of the site works fine, just the path to return PDFs fails, and I can't glean anything from the logs. Is this a known issue with wkhtmltopdf?
OS: Fedora
I had the issue with my node server program and wkhtmltopdf module in it, not generating pdf when run as a service. Turns out that a user for the service was set as nobody and so was usergroup. We removed that entry and reran the service it works.
I am guessing this could be the issue with Windows as well.
Please let me know if it did not work, did work or you already solved the problem with another approach.

Resources