Is there an idiomatic way of supporting multi domains?

Hi! We are coding a CMS like Wordpress and I’m trying to add support for multisite (i.e every site has a different domain) but I don’t know how to do it in an idiomatic way.
Also, the routes have to be different if I’m using it on my machine: points to the same page as http://localhost:4000/site/2/category/2 when running locally.

Right now I have duplicated my router code to handle the 2 different situations:

  • When the request comes from localhost
  • When the request comes from a different domain (e.g

The downsides of my approach are that it has a lot of duplicated code and I need make several helper functions to handle each case every time I want to show a different route depending on the hostname.

Is there another way of doing it? Any comment would be welcomed.
Thank you!

1 Like

While I have not being using such scenario, I think You might search for multi tenant.

This will give You…


Can you boil down the difference in the routing to a single change in routing that will always be different? Such as using always becomes /site/number? If so, then you can programmatically script something. But if not then you might be better off with different routers since your routing is different.


Maybe try factoring the duplicated routes into a second router and forward from the main router to the site router.

The site id could be extracted from the path or host and stored in the Conn.assigns.


But is there any limitation in using “” for localhost? Wouldn’t this allow you to keep exactly the same routing structure?
Then you would only need a plug to read and set the correct domain/subdomain before the controller resolving the controller action


Yes, because when I need to offer more functionality when running it locally. But I added the plug you said to make some things easier, thank you!