NodeJS '/' home route is working but the remaining routes are not working (CPanel Shared Hosting)

Mouhamed tall

Registered
Jun 21, 2021
4
0
1
France
cPanel Access Level
Website Owner
I have a problem when I deploy my NodeJS API on CPANEL shared hosting. My application is working very well on localhost but when I deploy it, the home route is the only one working, all remaining routes are not working (500 Internal error). I use Express.

JavaScript:
const express = require('express');
const cors = require('cors');
const app = express();
require('dotenv').config();

// Import Routes
const productsRoute = require('./routes/products');

// Middleware
const corsOpts = {
  origin: '*',

  methods: ['GET', 'POST', 'PUT', 'DELETE'],

  allowedHeaders: ['Content-Type'],
};

app.use(cors(corsOpts));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());


app.use('/products', productsRoute);
app.get('/hello', (req, res) => res.send('Hello World !'));
app.get('/', (req, res) => {
  res.send("OK");
});

app.listen();

Can somebody Help me please ?

Thank you !
 
Last edited by a moderator:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
16,597
2,617
363
cPanel Access Level
Root Administrator
Hey there! Can you let us know if you are seeing a specific error in the logs on the server related to that site? If not, you may need to open a ticket with our team, although our support would be limited to getting a test application working as outlined in our documentation here:

 

Mouhamed tall

Registered
Jun 21, 2021
4
0
1
France
cPanel Access Level
Website Owner
I use LWS hoster in France. I don't know if you can directly help me with a ticket. I use the NodeJS Setup rather than Application Manager as indicated in your documentation.
You can see the configuration on the attached file and my .htaccess has this generated code :
Code:
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/cp1125587p04/api-cosmeclass"
PassengerBaseURI "/"
PassengerNodejs "/home/cp1125587p04/nodevenv/api-cosmeclass/10/bin/node"
PassengerAppType node
PassengerStartupFile app.js
PassengerAppLogFile "/home/cp1125587p04/api-cosmeclass/api.logs"
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION BEGIN
<IfModule Litespeed>
</IfModule>
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION END
 

Attachments

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
16,597
2,617
363
cPanel Access Level
Root Administrator
If you have root access to the server, you can open a ticket with our team.

That interface is specific to the CloudLinux NodeJS tools, but I still don't have much information about routes in the documentation on our end. All the Express routing documentation can be found here:


so if that doesn't resolve the issue it would be best to speak with your host to see what options are allowed in that environment.
 

Mouhamed tall

Registered
Jun 21, 2021
4
0
1
France
cPanel Access Level
Website Owner
I solved the case after testing many methods. It was a passenger configuration problem
In my generated .htaccess file, I add the following lines on the top
Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /
RewriteRule ^server/(.*)?$ http://127.0.0.1:3000/$1 [P,L]
And in my nodeJS app I listen on port 3000

Thank you