Wednesday 26 September 2018

A lost traveler trying to find his way through this realm (Node.js, EJS, Apache, A2 Hosting)

Greetings all,Preface: I tried to post this in /r/webdev first but due to my low karma it got flagged and the mod hasn't approved my post yet so for now I will reach out here because I've already talked to some awesome people in this community who were very helpful before. So without further ado, welcome to my problems!I'm having some issues hosting a Node.js application on a shared/managed server that's hosted by A2 Hosting, which of course means I do not have root access on it (yes, I know I should be using a VPS but unfortunately I can't due to work restrictions). I figured I would post a little about it here just in case anyone can spot something I'm not seeing or maybe just point me in the right direction. I feel like I'm surprisingly close to having this thing actually work under these constraints and I'm super excited but it's also driving me insane. Any and all comments would be greatly appreciated!First, a little about the server itself - as I mentioned before it is a shared/managed linux server that is hosted by A2 Hosting and is running CentOS 6.x. The application structure and surrounding file system looks like this...(The ~/ represents the true linux /home/$user/ directory, not the web server root.) ~/ ├── public_html (Apache web server root directory) │ └── .htaccess └── myapp_repo (My Node.js app) └── myapp ├── app.js ├── bin │ └── www ├── node_modules │ └── * ├── package-lock.json ├── package.json ├── public │ ├── images │ │ └── img.png │ ├── javascripts │ │ ├── init.js │ │ └── menu.js │ ├── materialize │ │ ├── css │ │ │ ├── materialize.css │ │ │ └── materialize.min.css │ │ └── js │ │ ├── materialize.js │ │ └── materialize.min.js │ └── stylesheets │ └── style.css ├── routes │ ├── about.js │ ├── contact.js │ ├── index.js │ ├── send.js │ └── services.js └── views ├── about.ejs ├── contact.ejs ├── error.ejs ├── index.ejs ├── partials │ ├── banner.ejs │ ├── foot.ejs │ ├── head.ejs │ ├── menu.ejs │ └── script.ejs └── services.ejs I was able to install node and npm just fine and also configured my application to run on port 49157 because...To run a Node.js application on a managed server, you must select an unused port between 49152 and 65535 (inclusive). ^ directly from their docs.The next step that I took was figuring out how to re-route all web traffic to my node app instead of the apache root (i.e "~/public_html/"). I did that by writing a rather simple .htaccess file that routes everything to my loopback address at the port that I configured my app to listen on. It looks like this...$ cat ~/public_html/.htaccess RewriteEngine On RewriteRule ^.*$ http://127.0.0.1:49157/ [P,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d To my surprise after starting my application using $ nohup npm start --production &it was actually somewhat working when I visited my domain in my web browser. From what I can tell it seems like the HTML from my index.ejs file is rendering correctly but all the CSS and JavaScript is not (I linked bootstrap via their web link, hence the visible text styling). It looks like this...Obviously I immediately checked out those JS files and there is nothing wrong with them. I'm not really sure why I'm receiving those errors. Maybe one of my templates is inserting an extra character when it renders? I of course do not get this error when running it locally.Obviously I immediately checked out those JS files and there is nothing wrong with them. I'm not really sure why I'm receiving those errors. Maybe one of my templates is inserting an extra character when it renders? I of course do not get this error when running it locally.At first I thought it would be an easy fix, probably just the file paths had gotten a little offset from how I was running it locally on my dev machine but after trying every possible relative path and also absolute paths all the way from the root directory of the machine itself, nothing worked.Like I said before, this is driving me insane because I feel so close yet so far from getting this working correctly. I'm still new to building with node and also on the web in general so please pardon my stupidity in any and everything I have said or may say! I still feel like it's most likely a file path issue but I just can't seem to spot it. Again, any and all comments or suggestions would be super! Thanks for reading this and please feel free to comment and yell at me for being dumb because honestly... you're not wrong!

Submitted September 26, 2018 at 01:49PM by srclord

No comments:

Post a Comment