I have a somewhat complex and lengthy question.
I’m using Bun.js to run the backend API.
I want to use a load balancer for webify.rest
, and I want to distribute traffic across balanced sites behind that load balancer.
I generally know how to set this up, but there are some unclear parts I’d like to confirm or understand better:
- I create an API key at Hetzner and enter it in the VPS settings.
- I connect my GitHub account in the version control settings.
- I create a new server to act as the load balancer, naming it
webify.rest
. - I point the DNS for
webify.rest
to the IP of the load balancer server. - I set up a load balancing site on the server. Here, I’m unsure what App type to select for a Bun.js backend. I choose Static HTML since it seems the most minimal, enter
webify.rest
as the domain, and enable the free SSL option. - I create another server called
Api-01
, which will run the Bun.js API. I select Plain Server. - On
Api-01
, I manually install Bun and Nginx via Services (needed to create a site). - I create a site on
Api-01
, again using the Static HTML type, with the domain01.webify.rest
, and I skip SSL (since this is a balanced site). - I return to the load balancer server (
webify.rest
) and click “Link your servers.” I select theApi-01
server and click update. The site01.webify.rest
is automatically linked to the load balancer as a balanced site. - I open
webify.rest
in a browser and see the default “clear” landing page prompting me to deploy my app. - I go to the Deployment section and see two deployments, but they appear on the same level. Shouldn’t
01.webify.rest
be nested underwebify.rest
as part of the balanced group? Or is this normal? - I open the deployment settings for
webify.rest
(the load balancer), link the GitHub repository, and enter the environment variables under the Environment section. - I leave the deployment settings for
01.webify.rest
(the balanced site) untouched, assuming the load balancer handles deployment and that the balanced site inherits everything. Is that correct?
This is where things get blurry for me:
- When I push code to GitHub, the deployment process is triggered, and the files are uploaded to the server.
- However, after deployment, I need to run
cluster.js
and inject environment variables into the script. In development, I use:
bun --env-file=env/dev.env ./src/server/server/cluster.ts
How can I automate this so it runs every time after deployment?
- Once that’s resolved, how do I keep the app running? For example, how can I use Supervisor (or something else) to ensure the app stays alive and restarts with the correct environment variables if the server restarts?
My questions in short:
- Do I choose Static HTML as the site type and manually install Nginx and Bun?
- Is the deployment process I described correct?
- If I enter the environment variables in the load balancer, do the balanced sites automatically inherit them?
- How do I start
cluster.js
with injected environment variables automatically after deployment? - How do I use Supervisor (or similar) to keep the app running and restart it with env variables if the server reboots?
Apologies for the long message — I’d really appreciate your guidance on this.