Hey folks, I’ve created an example repo that I’ve made to show how you could add dynamic custom domains to a Phoenix app. I couldn’t find many resources on this out there, so I hope this helps! I’ll turn this into a guide as well some time soon.
What do I mean by dynamic custom domains?
Letting you or your end users connect multiple domains (i.e. something.com
is a domain) to your app at runtime, and likely returning data/content/responses specific to that custom domain.
Examples:
- A blog hosting platform allowing users to connect their own domain to only their blog
- An ecommerce platform allowing users to connect their own domain to their store
What does the example repo do?
- It’s a pretty standard Phoenix 1.7 app
- The example purpose being a blog host that lets you connect a custom domain to a blog.
- When you visit the custom domain, it should load only that blog and it’s posts.
- Otherwise, if you go to the primary domain of the app, it should load up the interface to manage blogs/posts.
- It uses liveview, to show how to handle websockets as well as http requests for custom domains.