Support for custom domains at DataHub Cloud
Support for custom domains at DataHub Cloud
Summary
- Situation: Currently user sites are available at
datahub.io
domain, at/@{username}/{projectName}/...
paths. - Problem: Some users, especially corporate clients, would like to use their own domain instead.
- Appetite: 2-4h
- Solution: mostly done, needs another app route
@domain/[domain]/[[...slug]]
and some middleware adjustments and testing
Situation
Currently user sites are available at datahub.io
domain, at /@{username}/{projectName}/...
paths.
Problem
Some users, especially corporate clients, would like to use their own domain instead.
Appetite
1 day
Solution
Dashboard UI part and logic related to custom domain configuration is already implemented and comes from the original vercel/platforms boilerplate.
High level overview
You bring your own domain (can be it's subdomain as well) and enter it in the dashboard.
After hitting "Save changes" the app will use Vercel API to set the domain in the Vercel's project:
Then you'll see current domain registration status below the input field.
Then you need to set A or CNAME records at your custom domain's registrar. After doing this the information under the input field will change and show you if the configuration is now valid.
Domain resolution to correct app route
Proposed option: Option A.
Option A: separate app routes for single-site URLs and custom domains
Custom domain is routed to another app route in the middleware.ts
file.
So we'd end up having:
/[username]/[projectName]/[[...slug]]
and- e.g.
/@domain/[[...slug]]
Core, repeated logic in both routes will be imported from a shared module.
❌ Option B: single app route for single-site URLs and custom domains
Custom domain is resolved in the middleware.ts
file to the corresponding username
and projectName
. Then, the request is "rewritten" to /[username]/[projectName]/[[...slug]]
(URL stays the same, i.e. with custom domain, but the same app route is used to render both single-site URL and custom domain ones.)
Why not:
- making a database call in the middleware can add latency to requests
- resolving wikilinks so that they link to the custom domain will require awkward additional db call in the slug page to find out if the site has custom domains set
Rabbit holes
- handling duplicate content between custom domain and single-site URL easy to solve and solved in the original boilerplate but for subdomains+custom domains
- option 1: redirect to custom domain if it's set; similar to https://github.com/vercel/platforms/blob/eeabcf1c8e29f5db86c15d71e98b8eded43bd341/app/%5Bdomain%5D/layout.tsx#L74-L81 makes it impossible to access the site at original single-site URL
- option 2: set canonical URL to custom domain if exists; similar to https://github.com/vercel/platforms/blob/eeabcf1c8e29f5db86c15d71e98b8eded43bd341/app/%5Bdomain%5D/layout.tsx#L50-L56 can access site both at custom domain and at original single-site URL
No-goes
- Making custom domain a premium feature in some way For now, let's just ship. For future we probably want a way to switch option to set domain on/off for a given site/project so that it can be tied to pricing tier. But that's the future