HTTP requests not reaching Node.js backend on server
I'm trying to set up a Node backend with a React frontend on a shared server running Apache and Cpanel. Both the back and front work fine and are able to communicate when I run both on my local machine. But I'm having trouble getting them to talk to each other on my production server. Full details are here: <3rd party link removed> and the full code is here: <3rd party Link removed>
As shown in the file tree on the update to the original post on stackoverflow, on my server I have the React build files in `/home/[user]/public_html`, so that they load on my homepage at <3rd party Link removed> . The Node app is in `/home/[user]/seedbank`, which mirrors the git repo above. Over SSH, I'm running `node server.js` from the `seedbank` directory and the app seems to start fine. But HTTP requests from the frontend don't seem to reach it in production. What do I have to do to make these communicate with each other? Is it an issue with the location of the files (e.g., having react in `public_html` and Node elsewhere)? I've exhausted my knowledge here, so any assistance is greatly appreciated. Thanks!
-
Hi @joelauerbach Though I did remove the 3rd party links, posting this to stackoverflow is where you'll most likely get the best results on this query, while we offer Node.js we don't provide support with its configuration. I can't troubleshoot a lot of this but I did read over the comments there and I believe in order to identify where the communication issue is occurring between the app and the production server the best advice was the following: [QUOTE]I'd recommend creating a stripped down app that just utilizes an IFFE to make a call to the API and the API responds back with a message. Bare essentials for the front and back-end. Rule out as many variables as possible. Then attempt to make that stripped down example work in a remote production.
Are you using our Node.js? You might check the documentation for insights on where to look for potential issues: Guide to Node.js Installations - cPanel Knowledge Base - cPanel Documentation0 -
Thanks for reading, @cPanelLauren. I had been using the Node.js graphical interface through cPanel, but my setup is slightly different than the one specified in the instructions you linked to. I'm on a shared server with Interserver, so I don't have root access. My host has instructions for Node here (I know you'll redact, but just for your own reference): Manage NodeJS Through cPanel - Interserver Tips. When I couldn't get this to work, I decided to try it via SSH, just running `node server.js` from the node app directory. The app itself seems to start fine, and confirms that it's listening on the correct port. The reason I haven't tried that suggestion to create a stripped down app yet is that I'm pretty sure the issue is with that last part: getting the example to work in a remote production. I would be just as lost on that step with a completely stripped down app as I am now, given that my back and front ends communicate perfectly when I run both locally and declare a "proxy" in the React package.json that points to the Node location and port. My existing app is also pretty minimal. Given that what it seems like I need to do is some equivalent of a proxy in production, my research so far has led to suspect that the answer might lie with the .htaccess file in my public_html directory. I'm currently trying this: ``` RewriteEngine On RewriteRule ^$ [P,L] ``` The theory being that my React frontend lives at my homepage corresponding to /home/[user]/public_html (which loads fine), and all I need to do is redirect https requests made here to my Node app, which is running from /home/[user]/[project]/[node]/server.js and listening on port 50000. Does that seem like the correct approach, as a general matter? Or is there some other setting I should be looking into? I've seen some suggestions that something called Passenger might also be a relevant factor. Really appreciate your help. 0 -
I'm not 100% on that rewrite rule - localhost to localhost/file may not function as intended - but before troubleshooting that I'm really curious since you're noting https requests - you're trying to get an outside application to connect with the web server over port 5000 but from what I'm seeing (if the XXX.XXX.126.19 IP is that of the webserver) the webserver seems to have that port closed (over TCP at least): nmap -Pn XXX.XXX.126.19 -p 5000 Starting Nmap 6.40 ( http://nmap.org ) at 2019-10-31 15:13 CDT Nmap scan report for domain.com (XXX.XXX.126.19) Host is up (0.042s latency). PORT STATE SERVICE 5000/tcp closed upnp Nmap done: 1 IP address (1 host up) scanned in 0.14 seconds
It's also open but filtered over udp, though I notice I can't reach anything for that IP on port 5000 even with curl:curl -vv https://XXX.XXX.126.19:5000 * About to connect() to XXX.XXX.126.19 port 5000 (#0) * Trying XXX.XXX.126.19... * Connection refused * Failed connect to XXX.XXX.126.19:5000; Connection refused * Closing connection 0 curl: (7) Failed connect to XXX.XXX.126.19:5000; Connection refused
Connection refused indicates a block as well.0 -
Ah, that's port 50000, not 5000 :) Sorry, too many zeroes. 50000 is the port my host recommended I use for Node. With my Node app running, nmap shows that it's open for me (with the service ibm-db2 instead of upnp). `curl -vv * Trying XXX.XXX.126.19... * TCP_NODELAY set * Connected to XXX.XXX.126.19 (XXX.XXX.126.19) port 50000 (#0) * ALPN, offering h2 * ALPN, offering http/1.1 * Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH * successfully set certificate verify locations: * CAfile: /etc/ssl/cert.pem CApath: none * TLSv1.2 (OUT), TLS handshake, Client hello (1): * error:1400410B:SSL routines:CONNECT_CR_SRVR_HELLO:wrong version number * stopped the pause stream! * Closing connection 0 curl: (35) error:1400410B:SSL routines:CONNECT_CR_SRVR_HELLO:wrong version number 0 -
Yea, that's entirely my fault - i was a zero short :( I do see that I'm able to connect and i get the same SSL error as you and it's due to the fact that SSL is enabled for 443 but not for 5000 which is being served by a separate service (as we are aware) and the SSL certificate is installed on Apache. I am a bit stumped with this one as well, tomorrow I'll see if I can get some further insight for you but ultimately this might be something we might need to defer you to a system administrator for. 0 -
Ok thanks, please let me know if you turn up anything. In the meantime, would it make sense for me to try to either open port 50000 for SSL or to have Node listen on 443? I"m just surprised at this whole debacle, because it seems like it would be a common use case. I feel like I"m missing something simple. 0 -
would it make sense for me to try to either open port 50000 for SSL
I would think so definitelyI"m just surprised at this whole debacle, because it seems like it would be a common use case. I feel like I"m missing something simple.
Me too, and I'm sorry I haven't had a chance to test this yet. I haven't forgotten though. Please let me know if you've made any progress as well.0
Please sign in to leave a comment.
Comments
7 comments