Ok, so my issue may be more on the nodejs side than caddy but if someone has any experience with something like this, it would be a huge help.
I’m building a SAAS project where customers can set up their own domain.
It’s a single-tenant project, which means each customer has its own database and codebase.
Each customer has access to a frontend and a backend, which are 2 different node projects.
Everything is dynamic, so I have no idea how to use the reverse_proxy with node.
I mean if I add something manually, it’s easy to use 2 ports per customers (one for frontend and one for backend) and to go like that.
But with a dynamic configuration, I don’t know how to handle node and its ports.
For now, I just use file_server to server an index.html but I need to start using my node project
Sorry, English is not my first language and I’m having problems explaining my issue.
Yes, but each customer has their own node app (2 apps per customer to be even more precise).
I don’t think I can use multiple node apps on the same port, so I must also use multiple ports. But everything is dynamic, so I’m unsure how to map my caddy file with a port I don’t know in advance.
Or maybe there is a way to do that differently but I have no idea.
If I had to to it manually it would be something like that
But it’s dynamic, I don’t know the domains in advance, so I don’t know how to assign a node port for each domain on the node side, and then map it in the caddy file.
This tells the proxy how to get the upstream dynamically at each request.
Currently there’s built-in support for reading upstreams from DNS records (A/AAA and SRV). You’d probably want SRV in your case. If you do that, then this should be a 1-liner for you.
If you want to give that information to Caddy another way (like checking a DB), you’ll have to write your own dynamic upstreams module. (It’s not hard, but you have to use Go.)
Another option (that I like less) is you could have your infrastructure update your Caddy config each time you spin up or down a node backend for a customer.
I will take a look!
Thank you for directing me to this documentation, I hadn’t found it.
By the way, I’m new to Caddy but I think it’s awesome. In just a few lines of config, I have something with dynamic domains and automatic SSL.
It’s impressive so thx you for this project
I was thinking, instead of using dynamic upstream (it’s a little complicated as I don’t have control of the domain names ; and it could be difficult to ask too many DNS changes to the customer).
Could I simply put the port in a txt file in my root and read it?