Environments, domains and TLS
Give Taskboard staging and production environments, point domains at each tier, and learn what the padlock checks: chain, hostname and expiry.
Deploying the three tiersEnvironment variables and secrets across layersCORS and cross-origin setups
Environments, domains and TLS
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Staging is a full copy of the stack with its own database, secrets and domain, so a risky change breaks a copy and not the product.
- Never point staging at the production database, and never reuse production secrets in staging, since staging is the environment people are least careful with.
- A domain is a set of DNS records: an A or AAAA record maps a name to an address, and a CNAME maps one name to another name that your host controls.
- A TLS certificate proves the server holds a key for a given hostname, signed by a chain that leads to a root your browser already trusts.
- Certificates expire, so use a host or tool that renews them automatically and check the expiry date as part of operating the app.
Why more than one environment
The first deploy goes to one place, and it feels fine. The second time you change something risky, a migration that renames a column or a change to the sign-in flow, you want somewhere to try it where a mistake costs nothing. That place is staging: a full second copy of the stack that looks like production but holds no real users.
An environment is more than a server. For Taskboard each one is a set of five things:
- an API deployment,
- a client build (with its own API URL baked in, as the previous lesson showed),
- its own Postgres,
- its own secrets (session key, OAuth client, payment test keys),
- its own domain.
A reasonable set is local (your laptop), staging (a deployed copy), and production. Some teams add a preview environment per pull request. The principle is the same each time: nothing is shared with production except the code.
The rules that prevent real incidents
- Separate databases. If staging and production share one, a bad seed script or migration run from staging is a production incident. It sounds obvious. It is also the most common way people lose data in a hurry.
- Separate secrets. Staging is where more people have access and checks are looser, so a production secret copied there is a production secret leaked. Use test-mode keys for payments and a different OAuth client for each environment.
- Same code path. Staging should differ from production only in configuration, never in
if (staging)branches. If the code differs, staging stops predicting production. - Fake data, or scrubbed data. If you copy production data to staging, remove emails and anything personal first.
A useful test: can you rebuild staging from nothing using only the repository and a list of environment variables? If not, staging has drifted into a pet you cannot recreate.
Domains are records
You buy taskboard.example from a registrar, then tell the DNS system where each name goes. DNS is a set of records:
- A (and AAAA for IPv6) map a name to an IP address.
- CNAME maps a name to another name.
- TXT holds proofs and settings, such as domain verification and email rules.
For Taskboard I would use:
| Name | Record | Points at |
|---|---|---|
taskboard.example |
A / ALIAS | the static host |
www.taskboard.example |
CNAME | the static host’s name |
api.taskboard.example |
CNAME | the API host’s name |
staging.taskboard.example |
CNAME | the staging client |
api.staging.taskboard.example |
CNAME | the staging API |
When your host gives you a name to point at rather than a fixed IP address, use a CNAME so the host can move your site without you editing DNS. I checked one real example: asking DNS for www.github.com returned a CNAME to github.com., and example.com returned plain A records. (I ran dig +short. The addresses will differ for you.)
Changes take time to spread because resolvers cache answers for the record’s TTL. Lower the TTL a day before a planned move, then raise it afterwards. For the underlying mechanism see domain names, DNS and hosting.
Putting the client and API on sibling subdomains of one registrable domain has a side effect worth knowing: cookies can be scoped to the parent domain and treated as same-site. That changes how you set SameSite and the cookie domain, which CSRF, XSS and cookie settings across layers covers.
What the padlock checks
HTTPS puts TLS under HTTP. The hard part of TLS is not the encryption but knowing who you are talking to. A certificate is the answer: a document saying “this public key belongs to taskboard.example”, signed by an authority. The browser comes with a list of roots it trusts, and checks three things:
- Chain. The server’s certificate is signed by an intermediate, which is signed by a root in the browser’s list.
- Hostname. The name you typed must be one of the names in the certificate.
- Validity. Today’s date is inside the certificate’s dates.
I looked at a real site to see these. Using openssl s_client (OpenSSL 4.1.0) against example.com:
issuer=C=US, O=SSL Corporation, CN=Cloudflare TLS Issuing ECC CA 3
subject=CN=example.com
notAfter=Dec 25 22:56:35 2026 GMT
Protocol: TLSv1.3
Verification: OK
The server sent four certificates, each one the issuer of the one before: the site’s, two intermediates, and a root. Asking OpenSSL to verify the same connection against the name taskboard.dev gave Verify return code: 62 (hostname mismatch), which is exactly the check a browser applies when a certificate is for the wrong name.
Note the validity window: this certificate runs for about three months. Short lifetimes are normal now, which makes renewal something that must be automatic.
Getting certificates in practice
For Taskboard you rarely handle certificates by hand. Static hosts and web-service platforms issue and renew a certificate for each custom domain you add, usually through the free ACME service Let’s Encrypt, once your DNS points at them. On your own server, a tool such as Certbot or a proxy with built-in ACME (Caddy) does it. In both cases the work is: add the domain, point DNS, wait for the certificate, then check.
Operate it like anything else:
- Redirect HTTP to HTTPS, and send
Strict-Transport-Securityonce you are sure HTTPS works everywhere. It tells browsers to refuse plain HTTP for your domain for a stated period. - Alert on certificate expiry, a few weeks ahead. Automatic renewal still fails sometimes, for example after a DNS change.
- Remember the database. If it is reachable over the internet, require TLS on that connection too.
Environment configuration, end to end
Put together, switching Taskboard between staging and production changes only data: the client build’s VITE_API_URL, the API’s DATABASE_URL, CORS_ORIGIN, the session secret, and the third-party keys. The API’s CORS allow-list is a good example of something people forget: each environment’s client sits on a different origin, so each API needs its own list. Keep these values in the host’s settings, not in the repository, as in environment variables and secrets across layers.
What the video covers
ByteByteGo’s “SSL, TLS, HTTPS Explained” is under six minutes, three years old, and by its title covers how TLS and HTTPS work. It covers the certificate and encryption half of this lesson. It does not cover staging environments or DNS setup, and I could not read a transcript to say how much detail it goes into on the chain of trust. For the environments half, Vercel’s “Environments on Vercel” is linked, but it is specific to that platform’s preview and production model.
Where this fits
Your app now has a name, a padlock, and a safe place to rehearse. The part most likely to hurt if it goes wrong is the data, so the next lesson is about hosting the database and proving you can get it back: database hosting, backups and restores.
Check yourself
What is the danger of sharing a database between staging and production?
A migration, a seed script or a bug in staging can modify or delete real user data, and staging often has weaker access controls and more people with credentials.
When do you use a CNAME instead of an A record?
When the host gives you a name to point at, such as taskboard.onrender.com, rather than a fixed IP address, so the host can change the address underneath without you editing DNS.
What three things does a browser check about a certificate?
That the chain of signatures leads to a trusted root, that the hostname you typed matches the certificate, and that it has not expired.
Why does the API need a different CORS origin list in staging and production?
Each environment's client is served from a different domain, and CORS allows only the origins you list, so a copy of the production list would block staging or allow the wrong site.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.