Navigation

Use a Custom Domain Name

On this page

Overview

You can use your own custom domain name for your hosted content. By default, content that you upload is available at a domain with the following form:

<Your App ID>.mongodbstitch.com

You can configure a custom domain name for your application’s hosted content from the Stitch UI or by importing an application configuration directory that specifies the domain in its stitch.json configuration file. Select the tab below that corresponds to the method you want to use.

Procedure

1

Acquire the Custom Domain Name

You must own the custom domain name that you want to serve content from. If you don’t already own the domain that you want to use, you will need to purchase it from a domain name registrar.

2

Specify the Custom Domain in Stitch

You need to provide your custom domain name to Stitch before it will serve content from the domain. To specify the domain:

  1. Click Hosting in the left-hand navigation.
  2. Click the Settings tab.
  3. Under Custom Domain, set the toggle to Enabled.
  4. Enter your custom domain in the input box under the Enabled toggle. This value should be the root domain without any subdomains. For example, you should enter example.com instead of www.example.com.
  5. Click Save.
3

Add a Validation CNAME Record

To verify that you own the domain you must add a new CNAME record in your domain’s DNS configuration. The Custom Domain section will include an information box that lists the host name and target value to use in the record.

Once you’ve added the validation record it may take some time for the DNS record to propagate. Stitch will periodically check the domain’s DNS records for the validation CNAME and will mark the domain as verified if it finds the record.

Note

Stitch may not be able to find the validation record if your DNS provider proxies requests for the domain. If Stitch cannot validate your domain, ensure that you have disabled any HTTP proxies for the validation CNAME record.

4

Add a Redirect CNAME Record

Once Stitch has verified your domain, all that’s left is to add a CNAME DNS record for your domain that points to the default Stitch domain. Use the following host name and target value:

Value Description
Host Name A subdomain such as www.
Target

The default domain for your application. This value is listed as the Stitch Domain in the Settings tab of the Hosting page. The default domain has the following form:

<Your App ID>.mongodbstitch.com
1

Acquire the Custom Domain Name

You must own the custom domain name that you want to serve content from. If you don’t already own the domain that you want to use, you will need to purchase it from a domain name registrar.

2

Export Your Stitch Application

To specify a custom domain name with stitch-cli you need to export an application directory for your application.

You can export your application from the Export tab of the Settings page in the Stitch UI, or by running the following command from an authenticated instance of stitch-cli:

stitch-cli export --app-id=<App ID>
3

Specify the Custom Domain

In stitch.json, set the value of hosting.custom_domain to your custom domain name then save the file.

"hosting": {
  "enabled": true,
  "custom_domain": "example.com"
}

Note

The value of custom_domain should be the root domain without any subdomains. For example, you should enter example.com instead of www.example.com.

4

Import the Application Directory

Once you have specified your custom domain name, you can import the application directory.

Navigate to the root of the application directory and run the following command:

stitch-cli import --include-hosting
5

Add a Validation CNAME Record

To verify that you own the domain you must add a new CNAME record in your domain’s DNS configuration. You can find the host name and target value to use in the record Custom Domain section of the Hosting > Settings tab in the Stitch UI.

Once you’ve added the validation record it may take some time for the DNS record to propagate. Stitch will periodically check the domain’s DNS records for the validation CNAME and will mark the domain as verified if it finds the record.

Note

Stitch may not be able to find the validation record if your DNS provider proxies requests for the domain. If Stitch cannot validate your domain, ensure that you have disabled any HTTP proxies for the validation CNAME record.

6

Add a Redirect CNAME Record

Once Stitch has verified your domain, all that’s left is to add one or more CNAME DNS records for your domain that point to the default Stitch domain. Use the following host name and target value:

Value Description
Host Name A subdomain such as www.
Target

The default domain for your application. This value is listed as the Stitch Domain in the Settings tab of the Hosting page. The default domain has the following form:

<Your App ID>.mongodbstitch.com