Skip to content

A React single-page app looks simple from the outside: a handful of static files behind a name. The DNS and HTTPS around it are rarely complicated, but they are easy to get subtly wrong, because the app usually talks to an API, may live on a subdomain, and is often deployed through a CDN that adds its own layer of certificates and caching.

This guide takes the DNS and HTTPS view of that picture. You will see which records a React app needs, how to plan subdomains for the app and its API, who issues each certificate, which headers are worth setting, and how to verify everything with tools you already have. If you want the step-by-step connection of a domain to a host, the sister article on connecting a domain to Next.js covers the server-rendered case, and the one on Squarespace shows a site builder in contrast. For a new name, begin on the domains page.

The path from a name to your files

A visit follows a fixed chain.

  1. DNS lookup. The browser asks a resolver for your name. The resolver follows the hierarchy to your domain's authoritative nameservers, which return the matching record, as described in RFC 1035.
  2. TCP and TLS. The browser connects to the returned address and negotiates encryption, presenting your name so the server can pick the right certificate.
  3. HTTP request. Over the encrypted channel, the browser requests index.html. The meaning of requests and responses is set out in RFC 9110.
  4. Static files. The browser then requests the scripts and styles named inside index.html.
  5. API calls. Once running, the React code calls your API, which may be on the same host, another subdomain or another provider.

Every arrow in that chain can fail on its own. DNS fails with the wrong address, TLS fails with a missing or mismatched certificate, HTTP fails with wrong routing rules, and API calls fail with cross-origin or mixed content errors. Treat them as separate checks, in that order.

Plan your names before you create records

A little planning saves repeated edits. Decide which names will exist.

Name Typical purpose Notes
example.com The main site, or a redirect to www Bare domain, uses A or ALIAS
www.example.com The main site, or a redirect to the bare domain Uses CNAME
api.example.com The backend your React app calls Separate record, separate server or provider
app.example.com The logged-in application, if the marketing site is elsewhere Keeps public pages and app apart
staging.example.com A test copy Keep it out of search results and protect it

Choose one primary address for the public site and redirect the other. For each name, write down where it points and who is responsible for its certificate. A short table in your project notes is enough, and it will save you hours when somebody asks months later why one subdomain shows a certificate warning.

The records you will create

Type Name Value Purpose
A @ Address supplied by the host Bare domain to the host
AAAA @ IPv6 address, if supplied Optional IPv6
CNAME www Hostname supplied by the host www to the host
CNAME or A api Hostname or address of your API Backend for the React app
CAA @ Authority allowed to issue Optional restriction
MX, TXT @ Email provider values Leave unchanged

A few rules explain this table.

  • A CNAME cannot share a name with other records. The bare domain always carries SOA and NS records, so it uses A (or an ALIAS-style record if your DNS service flattens aliases).
  • Take every value from the host's own screen rather than a tutorial. Values change.
  • Remove old records on the same name before adding new ones, or you will get inconsistent answers.
  • Keep the TTL low during a migration, then raise it afterwards.
  • Never edit the MX and TXT records that belong to email unless you are changing mail providers on purpose.

Who issues the certificates

Each name needs a certificate that lists it. The party that terminates TLS for that name is the one that must hold the certificate.

  • Front-end hosting platform. It requests and renews the certificate for the names you add. You supply correct DNS and avoid blocking validation.
  • CDN in front of storage. The CDN presents a certificate for your name. Some CDNs issue it for you; others let you attach one.
  • Your own server. Use an ACME client, which automates the proof of domain control and issuance described in RFC 8555, and configure Nginx or Caddy to use the files.
  • API on another provider. The API's host needs its own certificate for api.example.com. It is a separate item on your list, and it is often the one people forget.

If you run several subdomains, a wildcard certificate that covers one level below your domain can simplify management, though it also concentrates risk because a single key protects many names. If you are new to the topic, What is HTTPS? explains what the padlock really tells you and what it does not.

Step by step: front-end hosting platform

  1. Add the bare domain and www in the project's domain settings. Choose the primary one.
  2. Copy the records the platform displays. Create them at your DNS provider, deleting stale records for the same names.
  3. If your API is on a subdomain, create its record and confirm that the API host has a certificate for that name.
  4. Wait for the platform to show the domain as valid and the certificate as issued.
  5. Open both names over HTTPS in a private window. Confirm the padlock lists the right name and that the non-primary name redirects.
  6. Open a deep link directly to confirm the fallback to index.html works over HTTPS.
  7. Load a page that calls the API and open the browser's developer tools to look for blocked requests or certificate errors.

Step by step: your own server

  1. Build the React app and copy the build folder to the server.
  2. Configure Nginx or Caddy to serve the folder, with a fallback to index.html for unknown paths.
  3. Create A and CNAME records for the site, and a record for the API if it is separate.
  4. Open ports 80 and 443 in the firewall; many validation methods need port 80.
  5. Use an ACME client to obtain a certificate for every name you serve, and make sure renewal runs on a schedule.
  6. Redirect HTTP to HTTPS and the non-primary name to the primary name with permanent redirects.
  7. Test a dry-run renewal and note the expiry date.

Headers worth setting

Static hosts and CDNs let you attach headers to responses. For a React site, a few matter most.

Header Purpose Advice
Cache-Control on hashed assets Lets browsers keep scripts and styles Long lifetime is safe because the filename changes when the content changes
Cache-Control on index.html Makes new deployments visible Keep it short, or require revalidation
Strict-Transport-Security Tells browsers to use HTTPS for your domain Start with a short period; extend once renewal is proven
Content-Security-Policy Limits where scripts and other resources can load from Add gradually; a strict policy can block your own bundles and analytics
X-Content-Type-Options Stops browsers from guessing content types Safe to set to the standard value
Referrer-Policy Controls how much address information is sent to other sites Choose a conservative option

Change one header at a time, reload with the browser console open, and watch for blocked resources. If a header appears twice because both the CDN and the origin add it, browsers may combine or reject the values; set each header in one place.

API, cross-origin rules and cookies

The most common HTTPS-related breakage in React apps appears after the move to a custom domain, and it lives in the API conversation rather than in the static site.

  • Mixed content. A page served over HTTPS cannot call an HTTP API. The browser blocks the request. Serve the API over HTTPS and update the base URL in your configuration.
  • Cross-origin settings. If the app is on example.com and the API on api.example.com, the browser treats them as different origins and checks the API's cross-origin response headers. The API must list your site address explicitly. Using a wildcard together with credentials is not allowed, so list the exact origin.
  • Cookies. Cookies set by api.example.com are third-party relative to example.com only in some contexts. If you rely on cookies for sign-in, decide whether they are scoped to the parent domain, and mark them secure so they travel only over HTTPS. Review the same-site attribute, since the wrong value silently drops the cookie.
  • Redirect URLs. Sign-in and payment providers check the callback address. Update them to the new domain and the HTTPS scheme.
  • Environment variables. Public configuration in React is fixed at build time. After changing the API address, rebuild and redeploy.

Verify with simple tools

Check Tool Good result
Records dig or nslookup Values match the host's instructions for every name
Outside view A public resolver Same answers as your default
Certificate Browser padlock details or a command-line TLS client Right names, valid dates, trusted issuer
Redirects curl showing headers only Permanent redirects ending at the primary HTTPS address
Routing Open a deep link directly Page loads, no 404
API Browser developer tools, network tab No blocked or mixed-content requests
Renewal Dry run or platform status No errors, next renewal visible

Work in this order: DNS, certificate, redirects, routing, API. A failure in an earlier step makes later results meaningless.

Limits and what to watch for

  • Caching hides fixes. DNS, CDNs and browsers all cache. Test from another network and allow the old TTL to expire before deciding something is broken.
  • Different certificate per name. The certificate for the site may not cover the API subdomain. Check each name on its own.
  • Proxy mode conflicts. If a DNS provider offers a proxy mode, it can interfere with validation or with the origin certificate. Pause it while issuing, and follow your host's guidance.
  • Overly strict policies. HSTS and a strict content policy are valuable but unforgiving. Introduce them gradually.
  • CAA surprises. An old CAA record can block the authority your host uses.
  • Stale index.html. If the HTML file is cached too long, visitors keep an old version and may request scripts that no longer exist. Use short lifetimes for the HTML file.
  • Renewal failure. Automatic renewal depends on DNS and the validation path staying intact. Calendar a check of the expiry date.
  • Domain expiry. A valid certificate cannot save a lapsed registration.
  • Staging exposure. Test sites that reuse production DNS patterns can leak into search results. Protect or block them.

A worked example

Imagine a small learning platform with a React front end at learnloop.example and an API at api.learnloop.example.

  1. The developer decides the bare domain is primary and www redirects to it.
  2. At the DNS provider, an A record points the bare name to the front-end host, a CNAME sends www there, and a CNAME sends api to the API provider. MX and TXT records for email remain untouched.
  3. The front-end platform issues a certificate for the bare name and www. The API provider issues one for api.learnloop.example after validating the DNS record.
  4. The app configuration uses the HTTPS API address. The API's cross-origin settings list the exact site origin.
  5. The developer sets a long cache lifetime on hashed assets and a short one on index.html, then enables HSTS with a short period.
  6. Using curl and the browser tools, the developer confirms that redirects are permanent, deep links load, and the network tab shows no blocked requests.
  7. A calendar entry checks the certificates and the domain registration each month.

Summary

For a React app, DNS sends visitors to the host that serves your static files, and HTTPS proves the host belongs to your name. Plan every name, including the API, create the minimal records the host asks for, keep email records unchanged, and make sure each name has a certificate from whoever terminates TLS for it. Redirect to one primary address, keep API calls on HTTPS with the right cross-origin settings, set sensible cache and security headers one at a time, and verify in order: DNS, certificate, redirects, routing, API. Then keep an eye on renewals and the domain registration.

When you are ready to choose or bring in the name for the site, the domains page is a good place to begin.

Frequently asked questions

Which DNS records does a React single-page app need?

Usually an A or ALIAS record for the bare domain and a CNAME for www, both pointing to the host that serves your build files. If your API lives on a subdomain, add a record for it as well.

Should the API and the React app share a domain?

Either works. A separate subdomain such as api.example.com keeps things tidy but needs cross-origin settings and its own certificate coverage. Serving both under one domain can simplify cookies and cross-origin rules.

Does a wildcard certificate help a React app?

It can if you run several subdomains, such as app, api and staging, because one certificate covers them all. For a single site with two names, a certificate listing both names is enough.

Why does the browser block my API calls after enabling HTTPS?

A page served over HTTPS may not call an HTTP API; the browser blocks it as mixed content. Serve the API over HTTPS too and update the address used by the app.

Which headers matter most for a static React site?

Cache-Control for hashed assets and for index.html, Strict-Transport-Security once HTTPS is stable, and a content security policy if you can maintain one. Test each change, because strict values can block your own scripts.

About the author

Bob Kanokphon Thongdee, founder of XPASS VPN

Bob Kanokphon Thongdee

  • Founder of XPASS VPN
  • Co-founder of eSIMonline.asia
  • More than 7 years in online marketing
  • Founder of Cojourney Visa and Cojourney Travel

Ready to register your domain?

Search a name, compare extensions and pay once for the years you choose.

.com registration from $18.81 for the first year

Search domains

Keep reading

Domain & DNS Guides

How to Set Up DNS and HTTPS for a Next.js Site

A clear guide to the DNS records, certificates, redirects and checks that put a Next.js site safely on its own domain over HTTPS.

10 min read

Domain & DNS Guides

How to Set Up DNS and HTTPS for a Laravel Site

A practical guide to DNS records, certificates, HTTP-to-HTTPS redirects, HSTS and the Laravel settings that keep every link and cookie secure.

10 min read

Domain & DNS Guides

DNS and HTTPS Setup for Squarespace: What You Need to Do

What sits underneath a Squarespace domain: the DNS records involved, how HTTPS certificates are issued and renewed, redirects, caching and common errors explained.

10 min read