Thanks @luisherranz for all your help but unfortunately this isnāt working. I did find in one of their dialog notes that the custom variables when used for PORT are only available from within the server environment and not public.
Trying to start w/ port 80 or 443 fails as those ports are already bound to Apache which is serving those ports to the application path: node_modules/frontity/dist/commands.js serve
Iām going to open a ticket w/ FastComet and see if they are able to provide any input. Thanks again!
If I use the boiler plate file they provided - app.js and put that as the Application Path, it listens on port 443 - https://mysite.com/ and results in āIt Works!ā
Iām thinking it will probably require using file to bootstrap to another?
I saw another example image in their tutorial I linked in the first post where the server port was passed as a const to the server.listen command so Iām curious if I can use app.js cleverly to get this served up.
Yes, similar but there are differences and it really depends on the host offerings. Like Wordpress, there are many add-ons both core and 3rd party. NodeJS Selector is how they reference the Node feature.
FastComet told me this:
Note that indeed applications that are using in their configuration a hardcoded port it is not compatible with NodeJS Selector as the applications used by it are handled by the Passenger service on the server and no port required for it.
You can run more about Passenger in the following link:
Hereās what seems to work for me w/ Fastcomet hostingā¦
Create your domain/sub-domain as one normally would with cpanel. I chose to create a new sub-domain called āheadlessā in this example with the root folder being /headless in my hosting plan. I verified the DNS cname for headless also points to my Fastcomet server IP. I test a simple hello world html file to ensure all is good.
Back in the cpanel myriad of icons, locate the Node.js icon:
In this menu simply click ācreate applicationā
Nextā¦
choose the latest version offered of Node
set the environment to Production
set the application root to domain/sub-domain path, i.e. I chose āheadlessā and thenā¦
choose the actual sub-domain from the drop down
lastly, I show the app.js file in the image below but leave this blank, it will automatically be created for you
*the site should also be live in your browser now with a basic āit works!ā message.
Copy the highlighted path shown above and ssh to your hosting plan (Fastcomet has a tutorial on this) and paste the copied snippet which should put your in the folder of your sub-domain (i.e. /headless) which is also the application root path but this will allow /node_modules to install in the proper place (more on that later).
You should be aware another folder is created in your root hosting path called /nodevenv/ where another instance of your app/domain/sub-domain name lives as a folder and allows for the Node executables to live (I hope I am saying this correctly):
The files in the bin folder look like this:
ā¦back in our Node app/domain-path folder (/headless), execute npx frontity create headless (or your app name/path) doesnāt really matter because the npx runner creates the app folder which in this case will be a sub-folder within our cpanel app folder, again in my case āheadlessā within our original āheadlessā folder becauseā¦
npx frontity create needs the folder of which to be created to be empty or it wonāt run
we want to keep the original cpanel generated files (.htaccess, app.jsā¦)
we can just move the needed files easily into to our root app folder
The npx installation script should complete and the new /headless/headless folder is created along with /nodevvenv/headless/10/lib/node_modules/ (which is empty??? more on that in a sec)
*in the main app folder, (/headless), node_modules is sym linked to the virtual path /nodevenv/headless/10/lib/node_modules/
Next we fix our installation because if you remember the node_modules directory is still empty. We will fix this but first, for some reason, the theme installed in our app path /headless/headless/packages needs to be moved to the same folder our real node_modules folder lives otherwise future steps wonāt work. Copy the /headless/headless/packages folder to /nodevenv/headless/10/lib/ folder.
(to /lib folder):
Now that the theme is moved, copy all of the remaining files in /headless/headless/ to the main app /headless/ folder and back in the ssh terminal, also from the root app /headless folder execute npm install which will install all of the dependencies in /nodevenv/headless/10/lib/node_modules/
Now execute npm run build to create the /headless/build/ folder to create the final production version we be will serving to the public. (you can copy over this later with your final dev serverās files)
Edit the /headless/app.js file to now serve our frontity app:
var frontity = require("./build/server").default;
var http = require(āhttpā);
var server = http.createServer(frontity);
server.listen();
Back in cpanel Node.js area, restart the application and check the browser, you should now see your frontity app.
fyi - the theme files to edit exist at /nodevenv/yourapp/10/lib/packages/mars-theme/ and every time a change is made you must run from the /headless folder npm run build and then restart the app from cpanel.
Wow! Thank you very much @pingram3541, the guide is great! I will take a look with more detail. I was trying to do the same with SiteGround cpanel but Node is just available for dedicated servers and I have a shared one. I asked them and they are not planning to include it, so I wonāt be able to test it there.
Yeah I think it all depends on the host and if/how they support Node within their cpanel environment.
I saw a write up about installing Node @ SiteGround and it looked to be all via terminal commands which I expect to act much differently than via Phusion Passenger.
If I happen across another cpanel host and see Node.js and have the time, maybe Iāll see if these steps that worked at FastComet work elsewhere too.
This is both amazing (Phillipās tutorial) and amazingly difficult (the steps involved).
My take here is that we need to explore alternative ways, like recommending the PHP Theme Bridge and hosting the serverless function elsewhere or providing a one-click-install for cPanel.
Thanks again @pingram3541 for the detailed tutorial! Amazing work.
The 503 error might indicate that the web server service has not started. I guess you were following @pingram3541ās guide above. Did the previous 11 steps all work ok? Did you get any errors when you ran any of the commands in steps 7, 10, 11? If so, what errors did you get?
The issue lies here in this line of code as he copied code from @pingram3541ās guide and i think he accidentally places inverted commas instead of single/double quotes:
var http = require(āhttpā);
Replacing this will resolve the issue if 11 steps worked fine:
@pingram3541, amazing tutorial, but I have a small doubt at step 6: I should get the Node snippet PLUS an SSH generated key and paste it into the subdomain (headless, in your case). How should I paste it there? Is it a txt file? Should I upload the generated key file there? Sorry if I am asking a redundant question, but I have never done that before. Thanks!
Itās been a while since I have done this so things could have changed but no just copy the command provided (step 5) and then SSH into your hosting environment using your preferred SSH client then paste and execute that command from the command line.
The SSH generated key is for your SSH client to connect you to your serverās terminal giving you access to the command line interface where you will paste the copied snippet (command) and once executed, it will place you into the /headless folder (if you used same naming as my example).