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: http://site-2.com:4000/category/2 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:
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.
Can you boil down the difference in the routing to a single change in routing that will always be different? Such as using site-number.com 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.
But is there any limitation in using “yoursubdomain.lvh.me” 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