Anvil Community Forum

Multiple Domains

Is there anyway to have multiple custom domains pointing to the same app (and then choose a database based on the domain)?

Currently I just clone the app for each customer, but that leads to me having to maintain multiple copies of an app, which is a pain.

In the mean time, I’m investigating making a container app (which can be cloned and remains largely the same) that has all its features in sub-apps that are added as dependencies. That way a change to the published dependency becomes available to all.

How do others handle this situation?

You could create one branch per client, one environment per branch and in each environment decide which tables to share and which to duplicate, and which domain it’s published to.

After editing the development branch you will need to merge to each branch one by one.

I haven’t tried yet, but I think it should work with the new editor.

1 Like

That’s an interesting idea, thanks.

Yes, you can now do this with the Beta Editor!

You can set up a deployment environment for each customer, each with a separate domain. Each environment can point to a different database, but they can all point to the same branch so you can upgrade them all at the same time. (Or, of course, you can serve different versions of your code in different environments. But the merge-fest @stefano.menci suggests isn’t a requirement!)

I know you’re big on the Uplink, so you might be interested to know that you can connect Uplink separately to each particular environment (each env has its own uplink keys). Or, you can create uplink keys for one environment, then check Share Uplink with other environments and call those server functions from any environment!

Your code can use the environments APIs to work out which environment it is currently executing in, and show appropriate branding and behaviour.

(Please do give us feedback on how this system is to use! “Multi-tenant with a domain for each tenant” apps is a pattern we want to make easier with Anvil.)

2 Likes

Thanks @meredydd , I’m going to try this out tomorrow (thanks to the weather that’s going to be terrible) and I will feed back how I get on (which translates to “I will post daft questions as I stumble my way through”).

If the two apps are identical and the only difference is the database, then creating multiple environments, all pointing to the same branch, each with its own database is a good solution.

But creating one branch per client allows to have slightly different apps while maintaining only one. For example you could customize the styles or a form in one client’s branch and not in the other.

Workflow example:

  • create one dev and one client1 branch
  • work on the dev and when you are ready merge to client → at this point you have the app ready for the first client
  • your marketing works hard and finds a second client
  • create the third branch client2 on the same commit as client1 → now the two clients are using identical apps (and possibly different databases if that’s their environment setup)
  • you decide to add a feature for both:
    • make dev the editing environment
    • add your feature
    • make client1 the editing environment
    • right click on dev and merge to client1
    • make client2 the editing environment
    • right click on dev and merge to client2 → at this point both clients have the new feature
  • the second client only wants a new feature:
    • create a dev2 branch where client2 is
    • make dev2 the editing environment
    • add the new feature
    • make client2 the editing environment
    • right click on dev2 and merge to client2 → at this point only client 2 has the new feature
    • delete the dev2 branch. At this point it’s a good idea to delete dev too, just to decrease the chances of merge conflicts in the future
  • you want to add a new feature for both:
    • create a new dev branch either on client1 or client2, it doesn’t matter, just pick one
    • follow the steps above. At the end only the lines edited in the dev branch will be merged, you are not copying, you are merging only the modified lines

The difference between the clone approach and the multiple branches approach is that:

  • when you add a feature to both original and cloned app, you need to remember all the parts you touched on one app and do the same on the other. If the apps are identical, you can just copy the files, but if you customized one of the apps, then you need to manually apply the changes to the second app one by one
  • when you want to add a feature to both client branches, you edit once in the dev branch, then you merge it to both client1 and client2. Git will take care of merging only the lines that you modified since the last merge and leave any previous customization as is

PS: Notice that I have not mentioned the master branch in this workflow. I think that the master branch should be removed. It’s confusing and only makes sense in most other git workflows, I don’t think it belongs in Anvil.

You could reset it to an older branch so it’s out of the way, just like this:

image

Hmm…what you say also seems to make sense to me, as my clients might well have slightly different apps with a similar core.

Not so clear cut … need to think about this.

You could also throw dependencies into the mix! Your core could be one app with each client (or group of similar clients) having their own app with the core as a dependency.

1 Like

I think I like this way, but I am being very indecisive at the moment …