Serverfull hosting

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?

Hey there @nickg,

We’re right on top of this and we’ve actually split the dev-server already. I would love some help with pm2 to make this a regular deploy target. The ability to self-host is really important to me.

This is how you “run” the Serverless Functions:

  1. cd api; yarn add @redwoodjs/api-server
  2. NODE_ENV=production yarn api-server --functions ./dist/functions/ --port 8911

You would have to run the command in step 2 via pm2; and then you would proxy your requests in nginx to the process running on 8911.

They’re unfortunately AWS Lambda functions now, but we’re going to convert them into express and then make it so that they can be deployed to different targets.

Let me know if you need anymore help with this.

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.

Whoops! Yup! I’ll fix it above.

Thanks so much!