DEV Community

Julia for Light Cloud

Posted on Originally published at blog.light-cloud.com on

SaaS Part 4: Add Your Own Domain

SaaS Part 4: Add Your Own Domain

To add your own domain to an app on Light Cloud, open the environment's Domain tab, enter the domain, and add the CNAME and TXT records it shows at your DNS provider. Light Cloud verifies the domain and issues an HTTPS certificate by itself. For a SaaS, three things also need the new address afterwards: the APP_URL variable, the Stripe webhook endpoint, and any GitHub or Google sign-in callbacks.

In this tutorial the domain is app.example.com, a stand-in for yours. Wherever you see it, type your own domain instead.

What you will build

The app from part 3, on https://app.example.com instead of its light-cloud.io address, with HTTPS, and with sign-in, emails and payments still working.

Before you start

  • The app from part 3, running.
  • A domain you can add DNS records to, at whichever company you bought it from or that runs its DNS (your DNS provider).

Put the app on a subdomain such as app. or www., which works with every provider. A root domain such as example.com can't have a normal CNAME, so it only works if your provider supports CNAME flattening (sometimes called ALIAS or ANAME).

Step 1: Add the domain

  1. In the Light Cloud console, open the app, then Production , and the Domain tab.
  2. Under Custom Domain , click Add domain.
  3. Enter app.example.com, without https://, and click Save domain.

The Custom Domain card with app.example.com in the Domain name field and Save domain highlighted

The card now shows the domain as Pending and lists the three records to add:

The Custom Domain card: app.example.com Pending, and Add at your DNS provider with a CNAME app to light-cloud.io and two TXT records, _acme-challenge.app and _cf-custom-hostname.app, highlighted

Step 2: Add the DNS records at your provider

This step happens outside Light Cloud. Sign in at your DNS provider, open the DNS settings of your domain, and add the three records exactly as the Domain tab shows them:

Type Name / Host Value
CNAME app light-cloud.io
TXT _acme-challenge.app the value from your Domain tab
TXT _cf-custom-hostname.app the value from your Domain tab

The two TXT values are different for every domain, so copy yours with the copy button next to each one. In the Name or Host field, enter only the part before your domain, as in the table. Most providers add example.com by themselves.

If your provider can proxy traffic (Cloudflare's orange cloud, for example), switch it off for the CNAME, so the name points straight at Light Cloud.

Step 3: Wait for the certificate

Back on the Domain tab, click Check again. The console says changes usually show within minutes, sometimes up to 48 hours. Once the records are found and the certificate is issued, the domain turns Active :

The Custom Domain card with app.example.com marked Active

Open https://app.example.com. The app loads with a valid certificate. The light-cloud.io address keeps working too.

Step 4: Set APP_URL

Until now the app has worked out its own address from each request. That's why sign-in and email links worked before the domain existed. Now that the app has a permanent address, set it, so email links always use it:

  1. Open Production , Settings , and click Edit next to Environment Variables.
  2. Click Add , and enter APP_URL with the value https://app.example.com, without a slash at the end.
  3. Click Save.

The Production editor with the variables from parts 1 to 3, secrets hidden, and a new row APP_URL https://app.example.com, with Save highlighted

Saving deploys the app again. From now on, a link in an email sent from the old address still opens the new domain.

Step 5: Move the Stripe webhook

The Stripe webhook from part 3 still points at the light-cloud.io address. Change it to the new domain:

  1. In Stripe (still in test mode), open Developers , Webhooks , and your endpoint, and edit its destination. <!-- VERIFY: Stripe's labels, with the Stripe sandbox signed in -->
  2. Change the URL to https://app.example.com/api/auth/stripe/webhook and save.

The signing secret stays the same, so STRIPE_WEBHOOK_SECRET doesn't change.

Step 6: Check everything

On the new domain:

  1. Sign out and sign in again.
  2. Ask for a password reset and check that the link in the email starts with https://app.example.com.
  3. Upgrade a test workspace with the card 4242 4242 4242 4242, and check the plan changes. In Stripe, the webhook delivery shows 200.

If you added GitHub or Google sign-in, also add https://app.example.com/api/auth/callback/github and https://app.example.com/api/auth/callback/google to their OAuth apps.

Troubleshooting

The domain stays pending

The records aren't visible yet, or one has a typo. Check the CNAME from your terminal:

$ nslookup app.example.com


PS> nslookup app.example.com

Enter fullscreen mode Exit fullscreen mode

The answer should mention light-cloud.io. If it doesn't, compare the name you typed: some providers add the domain by themselves, so app.example.com typed in full becomes app.example.com.example.com. Enter only app as the name.

Sign-in redirects to the old address

APP_URL is missing or ends with a slash. Set it to https://app.example.com and let the redeploy finish.

Payments work, but the plan doesn't change any more

The Stripe webhook still points at the old address, or at a typo. Check the endpoint URL in Stripe.

Top comments (0)