Open hansmbakker opened 7 years ago
I have really no experience with node.js app. I know that the package FileBot-node is using node.js (I am using that package on my Synology). If I quickly look the internal structure of filenot-node.spk, it's very similar to what I create with my packager.
NB.: The package filebot-node is built with ant-spk. Maybe could you try it ?
In the application folder of filebot-node (the "client" folder under the package's "target" folder), I find a index.html file, which looks like a bootloader for the node-js application. This would be handled correctly by my packager. Do you have such an index.html file (client part) to access your app ? Or is your app only "server side"* ?
Next to the application folder "client", I see various folders ("data", "etc", "server") and shell scripts ("start" and "task"). It looks to me like those are just extra folders/files used by filebot-node itself (not by the DSM package deployment mechanism). If this is really the case, than I could easily manage the deployment of those too.
But for now, I would suggest to locate all extra files/folder in the application folder (i.e.: next to the index.html file).
Does what I say above makes sense to you ?
In the application folder of filebot-node (the "client" folder under the package's "target" folder), I find a index.html file, which looks like a bootloader for the node-js application.
https://github.com/filebot/filebot-node/tree/master/client-extjs This is the GUI for this app in DSM i suppose. That would not load nodejs
Do you have such an index.html file (client part) to access your app ?
The app has an app.js https://github.com/filebot/filebot-node/tree/master/server-nodejs which a start script start.sh
Which seems similar to this file https://github.com/filebot/filebot-node/blob/master/package/synology/target/bin/filebot-node-start Which in turn seems to be called by this start stop status script https://github.com/filebot/filebot-node/blob/9b60e56068e54f1886f8b7da362897676eb2e5f7/package/synology/scripts/start-stop-status
Or is your app only "server side"* ?
In case of filebot the "client side" is a synology GUI for the app as seen in the screenshot https://github.com/filebot/filebot-node
This is unusual though since most nodejs apps serve pages to the browser directly rather than having the app integrate within the ExtJS frontend framework used by DSM.
Some pieces would have to be in place for a "usual" nodejs app to work.
The tricky bit is where to serve the nodejs app on ... in particular which port. When you choose just any free port that will be easy but then users have to include the port number in the web address.
The normal port 80 and also the port 5000 are already taken by synology installed webservers (apache by default). Possibly nginx could be used as well but the principle stays the same.
I saw this page here https://github.com/vletroye/SynoPackages/wiki/DSM-CGI-Router-6.x of which i didn't know if it was a package or a technique used by the Mods packager. But anyway lets take a look at this existing solution from PHP and nodejs perspective. On the positive side solves a lot of problems mentioned in that writeup, so that's excellent. Now for the downsides ...
running php with cgi is a very old school way of doing things and will not be performant. The performance overhead comes in when starting php. So you will get delays in serving up the response. Also it might be more memory intensive because you start a new process for every user. This might be perfectly fine its just a small management app or something and you have just a handful users. The proper way would be to use php-fpm.
For nodejs i guess there would be possibilities to run over cgi as well. But again, very unusual (normally a long running process).
To run without cgi one would have to edit the synology apache configuration to act like some sort of reverse proxy to the php-fpm or nodejs app. Which can be dangerous when you do this for the apache process that serves port 5000 . Be sure to enable SSH before you do this otherwise you wont have a way to manage your NAS.
So what would technically be the more easy solutions for webapps now?
For "full featured" web apps you really would need to edit that apache configuration. When you use multiple domains you can let apache forward to the right app based on the incomming domain name. In that case, to the user it will seem that it is "just a website" ... as opposed to having synology domain with less performance.
Actually since nginx is more performant and these days most people prefer it, it would make more sense to take this as a starting point.
To get back the "plug and play" idea from cgi would be a bit tough as one still needs to edit nginx files. Possibly parts of the nginx configuration could be generated by the packager. This is not unheard of and actually not difficult if you have just limited things to configure. One could just write strings to a file or use a full fledged config generator such as https://github.com/digitalocean/nginxconfig.io and https://github.com/LinkedInAttic/nginx-config-builder
EDIT: seems that synology provides this functionality of configuring reverse proxy out of the box https://www.grahamleggat.com/blog/2017/8/21/synology-reverse-proxy-server Only limitation it seems that you can only forward to ports and not to sockets.
To have like a demo how to use Mods packager with nodejs or python serving on a different port would be really cool :)
I am on linux, maybe i will try to make it later. I think there is a big potential of (beginning) developers or people who just downloaded source code and want to try to run it on their NAS but have not yet found out about this packager. With some demos and keywords more people would come i think.
I downloaded https://github.com/vletroye/Mods/releases/download/v7.3-beta.1/ModsPackagerSetup.exe to give it a try
In the readme it says
The Web Station and the third party package Init 3rd Party are not mandatory anymore (See use of a CGI router).
However this package is still a dependency by default. After removing it from dependencies and running the package it offers me to download the file mods.php
I am not sure why this happened because i selected the Script option in the packager. Then made a simple script doing pwd
and ls
. Then in the going to the right of the dropdown with Script selected i see the path /webman/3rdparty/Raneto/mods.php
. Not sure why its pointing to this php file instead of the script i just created (which is in mods.sh).
Tried installing the web station, after that it still offers to download mods.php.
Raneto.spk.txt Remove .txt from filename
I probably have to review MODS as I did many changes and didn't retest everything properly.
I see your package is missing the cgi router and related nginx config + adhoc postinst script. Also, you don't have icons for your script (the item in this package) I did fix those "issues" and configured your package to open in a DSM Window by default.
Here is the resulting SPK: Raneto.spk.txt
I will read you previous post asap ;)
Regarding how to run a nodejs app, the easiest is for sure the option 1: to run in the background from the start script of the package, just as done by filebot-node.
Your option 2 is interesting as it sounds like it would not need the node server to listen on a port. You would, I presume, call node from the cgi, with the provided parameters ...
Is there a way to generate a package for a Node.js app (including the necessary node_modules dependencies)?