DEV Community

Michael Lee πŸ•
Michael Lee πŸ•

Posted on

How does one go about allowing custom domains to point to your application?

I've been mulling over a web application idea and was wondering how does one go about allowing users to set up custom domains to point to their said profile/account on the application?

For example, folks can set up a custom domain or subdomain to point to their Medium account.

I haven't thought through the entire stack yet, but let's say it's either Rails hosted on Heroku or AWS using a static site set up. Is this feasible and how would one go about setting this up?

Update I've provided a crude example of what I'd hope to achieve in this comment below.

Top comments (13)

Collapse
 
edwinthinks profile image
Edwin Mak • Edited

Hey Michael,

If you choose the Heroku + Rails route, you could get a custom domain through following these steps: devcenter.heroku.com/articles/cust...

If I'am understanding the question properly, I think this should be feasible and it should be a matter of setting up the DNS settings.

Hope I understood the question & this helps you :).

Best Regards!

Collapse
 
michael profile image
Michael Lee πŸ•

Hey Edwin! Thanks for chiming in. I think an example might help clarify what I'm trying to do.

Let's say my app is located at coolapplication.com

And let's say I have a user who's profile could be accessed at coolapplication.com/cooluser

Let's also say cooluser owns the domain cooluser.com and would like to point that domain to their profile on my application. So that when folks visit cooluser.com what gets shown is their profile on my application coolapplication.com.

Hope this clarifies things and wondering if your suggestion still applies to this :)

Collapse
 
edwinthinks profile image
Edwin Mak

Ahh Michael.

Thanks for clarifying!

In that case, I don't believe the heroku guide will help you in your pursuit :(

However, it looks like this person on stack overflow is aiming to do something very alike - stackoverflow.com/questions/224652...

^ there is an answer there which doesn't seem to have any response or thumbs up. Wondering if this will help.

Best wishes :)

Thread Thread
 
michael profile image
Michael Lee πŸ•

Thanks Edwin for sending me your best wishes :) and lending me your Google-foo skills. Will definitely have a look as I continue my quest to achieve this solution.

Collapse
 
joshualjohnson profile image
Joshua Johnson

You'll want to look into provisioning your server with VirtualHost configurations in Apache.

Collapse
 
michael profile image
Michael Lee πŸ•

Thanks Joshua for sharing your reply. So you're saying it's a setup on the server level and not the application level? Or perhaps a combination of both?

Collapse
 
joshualjohnson profile image
Joshua Johnson

How you really want to handle it, is for each client, setup a different instance of the application. You can handle this in multiple ways. VirtualHosts are typically how we assign custom domains to their perspective instance.

1) Point the A Record of the domain to the IP of the server you intend to serve the application from.
2) Configure the server to accept the domain and serve your application.

I need to know more about the problem you are trying to solve before I can give you a solid solution for how you might host the application/server configuration. I could jump on a call and give you some direction once I hear more about what you are trying to accomplish.

Thread Thread
 
michael profile image
Michael Lee πŸ•

I've add more details of what I'm trying to achieve on this comment.

Basically for folks to set up a profile, then at some point if they want, they can point a custom domain to said profile and it would show their profile on the application when folks hit their custom domain.

Thread Thread
 
joshualjohnson profile image
Joshua Johnson

Like a blog platform would does this type of thing?

In that case, I would say that you can host within a single application. However, at the server level is where you would configure your VirtualHosts so that you can serve the application with different domains. At the application level, you will want a way to associate the custom domain with the client profile.

Thread Thread
 
michael profile image
Michael Lee πŸ•

Yeah, I think the easiest comparison to the idea is a blog platform. Where a user can create content and "publish" it to the account on the platform I'm creating and then point their custom domain to it.

Thanks Joshua for the guidance! Think you've set me on a good path :)

Thread Thread
 
joshualjohnson profile image
Joshua Johnson

No problem! Glad to help!

Collapse
 
jackharner profile image
Jack Harner πŸš€

You're looking to do essentially what GitHub Pages does with the custom domains.

Just a rough draft thought I'm having this morning but I would think you could have a database connecting the custom domains to profile IDs or whatever and then have a bash script that runs every 15 minutes that would then go create or destroy the (assuming Apache) VirtualHosts files pointing the domains to the profiles.

There's probably a more dynamic/optimized way to do that but it might work?

Collapse
 
carterbryden profile image
Carter Bryden

Late to the show here, but generally you need:

  1. Something to generate/renew/manage SSL certs for each custom domain (and to handle random events like certificates being revoked by a certificate authority)
  2. Something to route custom domain traffic to your app
  3. Something to filter out requests for custom domains that your app hasn't approved
  4. Some way for your app to know what to do with requests for each custom domain (load specific content, for instance)
  5. Maybe handle distributed routing, if your app is globally distributed or on something like vercel, firebase, AWS lambda, etc. - this can be especially tricky to build and manage well.

If you want to build and manage this yourself, your best bet is probably Caddy Server, which can handle some of this out of the box, and all of it with some effort (and learning curve).

Another easy and affordable way to do this is with approximated.app, which will handle all of this for you for around what you'd spend doing it yourself. Note: I'm the founder, so I'm both biased and open to questions (about any of it) if you've got any!