To add a staging site to a SaaS on Light Cloud, push a staging branch. Light Cloud creates a Staging environment with its own address. Then give it its own PostgreSQL database by setting DATABASE_URL on that environment, and set a visitor password on its Security tab. Staging then runs the same code on the same infrastructure as production, but test sign-ups never reach your customers' data.
In my run the Staging environment appeared 2 seconds after the push, and the password page was up 12 seconds after I saved the password.
What you will build
A second copy of the app from part 4, on its own address and behind a password:
| Production | Staging | |
|---|---|---|
| Branch | main |
staging |
| Address | your domain from part 4 | staging-tutorial-saas-starter-yourworkspace.light-cloud.io |
| Database | saas-db |
saas-staging-db |
| Visitors | everyone | only people with the password |
Before you start
- The app from part 4, running.
- A plan with two databases. Lite includes one, so I ran this on Starter. Pricing lists what each plan includes.
- Git and a clone of your fork:
$ git clone https://github.com/YOUR-USERNAME/tutorial-saas-starter.git
$ cd tutorial-saas-starter
PS> git clone https://github.com/YOUR-USERNAME/tutorial-saas-starter.git
PS> cd tutorial-saas-starter
Why staging needs its own database
A new environment starts with the variables you set when you created the app in part 1: APP_NAME, EMAIL_FROM, AUTH_SECRET and DATABASE_URL. So a fresh staging environment talks to the production database until you change that. Variables you added later on Production , like the Stripe keys and APP_URL, stay on Production.
That's why the database comes first in this tutorial, before the branch.
Step 1: Create the staging database
- In the Light Cloud console, click New... , New Database.
- Name it
saas-staging-db, keep Size at Dev , and click Create database. Mine was ready within seconds. - On its Credentials tab, choose Connect from: Node.js and copy the Connection String , as in part 1.
Make a second AUTH_SECRET too. Staging is where you share passwords and test accounts with other people, so keep its secrets apart from production's:
$ openssl rand -hex 32
$ openssl rand -hex 32
On Windows, run it in Git Bash.
Step 2: Push the staging branch
$ git switch -c staging
$ git push -u origin staging
PS> git switch -c staging
PS> git push -u origin staging
Auto-create environment per branch is on by default, so Light Cloud builds the branch by itself. The app's Environments tab lists Staging next to Production , and the sidebar shows staging under the app. My first staging build was live 7 minutes after the push.
Open Staging , then Settings , and look at Environment Variables. The card says which ones came from the app:
That first build ran on the production database. The migrations had nothing to do there, so it changed nothing, but it's the reason for the next step.
Step 3: Give staging its own variables
- On the Environment Variables card of Staging , click Edit. The editor lists the inherited variables with their values, ready to change.
- Set
APP_NAMEtoRota Planner (staging), so nobody mistakes one for the other. - Replace
AUTH_SECRETwith the new secret, andDATABASE_URLwith the staging connection string. - Click Save.
The editor shows the inherited values in plain text, production's database password among them. Edit it where nobody is looking over your shoulder.
Saving redeploys staging. On start it runs the migrations against the empty staging database. The Logs tab shows Database migrations are up to date. again, and saas-staging-db now has the app's 10 tables and no users.
Staging has no Stripe variables, so billing is off there. If you want to test payments on staging, add a second webhook endpoint in Stripe's test mode that points at the staging address, and set the four STRIPE_ variables on Staging , with that endpoint's signing secret.
Step 4: Set a password
- On Staging , open the Security tab.
- Under Password Protection , click Set password.
- Enter a password twice and click Save password.
Store the password before you save. The console says so too: it's hashed on save and can't be shown again. The card then says This site is password protected :
It applies to staging only, and without a redeploy. Open the staging address in a private window and you get the password page first:
From the terminal you can see what search engines get:
$ curl -I https://staging-tutorial-saas-starter-yourworkspace.light-cloud.io/
HTTP/2 401
x-robots-tag: noindex, nofollow
PS> curl.exe -I https://staging-tutorial-saas-starter-yourworkspace.light-cloud.io/
HTTP/2 401
x-robots-tag: noindex, nofollow
Put a password on a staging site covers the password page in more detail.
Step 5: Try a change on staging
Make a visible change on the staging branch. In src/lib/plans.ts, change the Pro plan's description:
description: "For small teams shipping every week, now with email support.",
$ git commit -am "Pro plan: mention email support"
$ git push
PS> git commit -am "Pro plan: mention email support"
PS> git push
Staging redeploys and shows the new text on its pricing page:
Production still shows the old one:
Step 6: Promote staging to production
When staging looks right, merge it into main:
$ git switch main
$ git pull
$ git merge staging
$ git push
PS> git switch main
PS> git pull
PS> git merge staging
PS> git push
Production redeploys from main with its own variables, database and domain. Mine took 4 minutes 18 seconds, shorter than the first build in part 1. Keep the staging branch for the next change. If you delete it, Light Cloud removes the staging environment with it.
Troubleshooting
Staging shows the same users as production
Staging still uses the inherited DATABASE_URL. Set it on the Staging environment, save, and let the redeploy finish.
The staging password page doesn't appear
You opened production, or a browser that already entered the password. Try a private window on the staging address.









Top comments (0)