First, what a great framework. I see there is a definite focus on serverless, which is great for startups and middle to large businesses and a great benefit to scalability.
However, I’m a freelancer and have a lot of smaller clients and host my own Linux server with node.js instances in PM2 with a reverse proxy in Nginx. I was looking into deploying an example Redwood app to my own Linux server. When I build the project, the web/dist output is simple enough - just files to host in Nginx (yay JAMstack!).
However, how can I host the function artefacts in api/dist? Do these conform to a spec like the serverless framework and how can I deploy them to PM2? Or do I need to use something like OpenFAAS or the Fn Project?
Thanks! It’s working locally here. I’m very happy the ability to self-host is important to you. I was afraid Redwood was being too dependant on cloud providers.
However, I think you made a mistake, you meant @redwoodjs/api-server instead of @redwoodjs/api, right? Also, I think you want to add it to non-the dev dependencies for production: yarn add @redwoodjs/api-server
I’m going to play with this with PM2 when I have some time later this week. I’ll upload an example repo if I have something working if you want to take a look.
It would be nice to have .env loaded in api-server. Now I have to explicitly load dotenv in the node_args in the PM2 configuration.
I map the API at /api (how creative eh), but the links in the root refer to absolute paths instead of relative paths. I could create a pull request for that, but I think one would actually prefer to not expose all the functions at that root API page (in production mode)?
Shall I create a cookbook recipe based on this for the Redwood site? I think it will help a lot of people.
Hmm, I think there should be a boundary somewhere… Perhaps the responsibility of the hosting solution should be up to the user? For example, one could prefer to use Forever or Phusion Passenger (which I did for a while because of hosting Rails apps).
Also, because PM2 is a hosting and deploy tool, there is always some specific config necessary for PM2. How do you expose this functionality to the user? A simplified config file, or does the user provide a PM2 config file which overrides Redwood defaults? Something extra to think about.
Still, I think it could be nice to have an integrated PM2 option as long as there is the option of using something else.
one thing I can offer here is making this into a “push button” deploy based around Pulumi - if you think that’s something that would be useful. my experience interviewing redwood devs is that even if they can set up some of the infrastructure you describe here, they sure would prefer not to!
well within realm of possibility to have this setup the all the requirements you list, and return to the user keys so they can ssh onto the machine + IP/host info + a deployment script.
I don’t see you on discord but would love to chat further…
If you were to host RW on something like Linode Shared Compute, what would be the minimum specs to go for? And what would the limiting factors be? I.e. what limit would you most likely hit first? (Let’s assume that apart from hosting your RW app serverfully, the rest of the app is “jamstacky”, so your DB is on something like Heroku, your files are on Filestack, your images on ImageKit etc.)
Usually you’ll know if you can and want to self-host, since you need a little more Linux knowledge than the occasional sudo apt upgrade. Of course you can automate the setup, but the user also needs to understand there is configuration and upkeep for things like security, database, backups.
About performance, it depends on the app, but my minimum example only needs 40MB memory. I’ve got 7 (arguably small) production sites running on a VPS instance with 1GB memory. A mix of Rails and Node. This also runs Postgres, no need for an extra service. I have other, heavier sites on their own VPS.