node.js app HTML file not loading external resources
Hi all,
I have a peculiar issue that maybe someone can help with?
I've set up a node.js app in cPanel which is working fine - http://cache.4x4tyres.co.uk/sitecache/ but on a particular endpoint http://cache.4x4tyres.co.uk/sitecache/test I am just using -
app.get(root + '/test', (req, res) => {
res.sendFile('index.html', { root: __dirname });
});
which just sends the contents of the `index.html` file to the browser.
If you look at the console for the above URL, you will see that there it's trying to load a .js file called `load.js` - this is just something I'm testing to check that I can load external resources in the HTML. This is giving me a 404.
The contents of `index.html` are simply:
<!DOCTYPE html>
<html>
<head>
<title>Test HTML file</title>
<script src="/load.js"></script>
</head>
<body>I'm a simple html file</body>
</html>
I believe that this same issue would arise if I tried to use something like `socket.io` which relies on an external resource being loaded in the html file.
So the question I have is how do get external resources like this loading properly in a cPanel node.js application?
As a I side note, I also noticed that when I set up the node.js app, it also created me a `sitecache` directory in `public_html` and in there is a new `.htaccess` file with the contents:
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/cache4x4tyresco/apps/sitecache"
PassengerBaseURI "/sitecache"
PassengerNodejs "/home/cache4x4tyresco/nodevenv/apps/sitecache/12/bin/node"
PassengerAppType node
PassengerStartupFile app.js
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END
Not sure if that is relevant here, but thought it best to include.
Many thanks
Kevin
-
Hey there! Our support for Node.js is limited to ensuring a default application works as outlined at https://docs.cpanel.net/knowledge-base/web-services/how-to-install-a-node.js-application/. If there are issues with that process you'll need to submit a ticket so we can take a look at the system.
0 -
cPRex - hi there, just a follow up on this, I have managed to get a node.js app up and running on cPanel and loading socket.io by using the following in my /public_html/.htaccess file:
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN PassengerAppRoot "/home/cache4x4tyresco/apps/testapp" PassengerBaseURI "/" PassengerNodejs "/home/cache4x4tyresco/nodevenv/apps/testapp/12/bin/node" PassengerAppType node PassengerStartupFile app.js # 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
BUT - this conflicts with my WordPress rewrite rules which are:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>Basically with the WordPress rules in my .htaccess my node.js app's index.html file does not load socket.io (it gives a 404 error), however if I comment the WordPress rules out, it works fine, but then WordPress doesn't work (apart from the homepage). Doesn't seem to make any difference what order these blocks are in my .htaccess file either.
Don't know if you'd call this a bug, but there must be some way for WordPress and a node.js app using socket.io to exist on the same domain? Or not?
Kevin
0 -
I actually don't think having two types of content on the domain is intended in a cPanel environment. When you start using Node for things, you're all in.
0
Please sign in to leave a comment.
Comments
3 comments