[help] Nodejs app alongside Prestashop instance on the same virtual server

papiez2137

Registered
May 14, 2021
3
1
3
Vatican
cPanel Access Level
Website Owner
I want to run nodeJS app which sole purpose is just to make some redirects based on DB queries, the app resides on main domain let's say example.com.

On a subdomain shop.example.com there is a prestashop 1.7 installed.

The virtual server software is cPanel.

Prestashop instance works as long as I don't install the node app, when I do it seems to make both example.com and shop.example.com unresponsive, and after a while it returns 503. The node app runs on port 8080.

Node app connects with the firebase instance. when the url is in the format `example.com/aS7vXbSDn9` it should ask the DB if an entry with that ID is present and redirect based on that entry value


I have posted this question on stackoverflow 9 months ago and even offered a bounty but no success. Please help, it's a business Idea I had which is stalled by this sadly
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
7,494
1,009
313
cPanel Access Level
Root Administrator
Hey there! This sounds like an issue with the Node.JS vhost taking over for the subdomain as well, causing the content in the subdomain to not be served properly.

I'd recommend reviewing our guide at How to Install a Node.js Application | cPanel & WHM Documentation as that is the only way to get Node.JS to properly interact with cPanel. Even then, our support is extremely limited, but we'd be happy to check your server's configuration through a ticket if you're not able to get a test app to work properly with those steps.
 
  • Like
Reactions: papiez2137

papiez2137

Registered
May 14, 2021
3
1
3
Vatican
cPanel Access Level
Website Owner
Thank you! The problem was that my app entry file was named index.js instead of app.js.
Renaming to app.js fixed the issue!

Now the only problem I have is that my express app handles also the requests from the subdomain - it shouldn't do that. But I reckon you don't know anything about Express.js so I will be nagging someone else now :) thanks!
 
  • Like
Reactions: cPRex

papiez2137

Registered
May 14, 2021
3
1
3
Vatican
cPanel Access Level
Website Owner
ok so I am fighting with this for so long already, you guys are my only hope
even stackoverflow and Discord programming/devops groups wouldn't help me (did not get any answers)

fixing the app filename helped for 503 error, but now I am struggling to have Prestashop working.

I figured my problem is not caused by Express app by itself, but wrong routing rules?

I did long hours of research but I guessmy devops knowledge gap is just too big, anyway, found different solutions using for example Virtual Host (which I cannot try because the server is a VPS - already asked the support and they suggested trying with htaccess)

my current .htaccess in root directiory
Code:
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/domain/public_html/approot"
PassengerBaseURI "/"
PassengerNodejs "/home/domain/nodevenv/public_html/approot/10/bin/node"
PassengerAppType node
PassengerStartupFile app.js
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule /(.*)?$ https://127.0.0.1:8080/$1 [P]
</IfModule>
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php73” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
tried various approaches found in different parts of the inernet like:

Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^shop/(.*[^/])/?$ https://127.0.0.1:443/ [P]
RewriteRule /(.*)?$ https://127.0.0.1:8080/$1 [P]
</IfModule>
but needless to say none of them worked.

TL;DR basically need to have node server with 1 endpoint working on root domain

`domain.com/`

and prestashop on subdomain

`shop.domain.com/`

right now any requests to that subdomain result in the same response as `domain.com/`

if I call something like `shop.domain.com/subpage` then it works normally, so I have certainity Prestashop instance is working fine. it's just NodeJS Express app steals all requests to that subdomain root


please please help me, I am so desperate already