Subdomains & Access Management โ
Guide for creating new subdomains, managing Cloudflare Access policies, and maintaining security.
Table of Contents โ
Domain Structure โ
Our domain structure follows this pattern:
ourlantern.app
โโโ ourlantern.app (production root)
โโโ dev.ourlantern.app (development staging)
โโโ docs.ourlantern.app (documentation site)
โโโ docs.dev.ourlantern.app (dev documentation)
โโโ storybook.ourlantern.app (component library)
โโโ storybook.dev.ourlantern.app (dev component library)
โโโ api.ourlantern.app (future: backend/API)
โโโ blog.ourlantern.app (future: marketing site)Current Domains โ
| Domain | Environment | Purpose | Access Policy |
|---|---|---|---|
ourlantern.app | Production | Main app (live) | lantern-app (PIN) |
dev.ourlantern.app | Development | Team testing/staging | lantern-app-dev (PIN) |
docs.ourlantern.app | Production | Documentation site | Public (or PIN if restricted) |
docs.dev.ourlantern.app | Development | Dev documentation | Public (or PIN if restricted) |
storybook.ourlantern.app | Production | Component library | Public (recommended) |
storybook.dev.ourlantern.app | Development | Dev component library | Public (recommended) |
*.ourlantern.app | Any | Catch-all wildcard | lantern-app-wildcard (PIN) |
Creating New Subdomains โ
Scenario: Adding a New Subdomain (e.g., api.ourlantern.app) โ
Step 1: Code Your Feature โ
Create a feature branch and develop your subdomain code:
git checkout -b feature/api-endpoint dev
# ... implement API functionality ...
git push origin feature/api-endpointStep 2: Test on Preview URL โ
Cloudflare auto-generates a preview URL:
https://feature-api-endpoint.lantern-app-dev.pages.dev- Already protected by dev Access app
- Test thoroughly before proceeding
Step 3: Merge to Dev โ
git checkout dev
git merge feature/api-endpoint
git push origin devResult: Deploys to dev.ourlantern.app for staging.
Step 4: Add DNS Record in Cloudflare โ
- Go to Cloudflare Dashboard โ DNS
- Click Add record
- Configure:
- Type: CNAME
- Name:
api - Content:
lantern-app.pages.dev(or your prod project) - Proxy status: Proxied (orange cloud)
- TTL: Auto
- Save
Step 5: Create/Update Access App โ
Option A: Use Wildcard App (Recommended)
- The existing
lantern-app-wildcardapp already protects*.ourlantern.app - No new Access app needed
- New subdomain automatically inherits PIN policy
Option B: Create Specific Access App
- Go to Cloudflare Zero Trust โ Access โ Applications
- Click Add an application โ Self-hosted
- Configure:
- Application name:
lantern-app-api - Domain:
api.ourlantern.app
- Application name:
- Add same PIN policy as other apps
- Save
Step 6: Deploy to Production โ
Once tested in dev:
git checkout main
git merge dev
git push origin mainResult: Lives at https://api.ourlantern.app (protected by Access)
Access Policies โ
Current Access Setup โ
Three Access applications protect our domains:
lantern-app(Production)- Domain:
ourlantern.app - Policy: One-time PIN
- Purpose: Main app, live users
- Domain:
lantern-app-dev(Development)- Domain:
dev.ourlantern.app - Policy: One-time PIN
- Purpose: Team testing/staging
- Domain:
lantern-app-wildcard(Catch-all)- Domain:
*.ourlantern.app - Policy: One-time PIN
- Purpose: Protect any future subdomains automatically
- Domain:
Modifying Access Policies โ
Change Authentication Method โ
For example, switch from "One-time PIN" to "Email Domain":
- Go to Cloudflare Zero Trust โ Access โ Applications
- Click the app name (e.g.,
lantern-app-dev) - Click Edit
- Go to Policies tab
- Click your existing policy
- Change Require from "One-time PIN" to "Email addresses":
- Add allowed email addresses (e.g., team members)
- Save policy
Add a New Policy โ
Example: Allow GitHub organization members:
- Go to Applications โ Click app โ Edit โ Policies
- Click Add a policy
- Configure:
- Action: Allow
- Include rule:
- Selector: GitHub Organization
- Value: Your org name
- Session duration: 24 hours
- Save
Remove/Disable a Policy โ
- Go to Applications โ Click app โ Edit โ Policies
- Click the X button on the policy to delete
- Save
Session Management โ
Adjust how long users stay logged in:
- Click app โ Edit โ Click policy
- Under Session duration, choose:
- 15 minutes (most secure)
- 1 hour
- 24 hours (current default)
- Custom duration
- Save
Testing Workflows โ
Testing New Subdomains Locally โ
Since new subdomains require Cloudflare DNS, test locally first:
# In your dev server, you can test by mocking the subdomain
# For example, test API logic without hitting Cloudflare DNS
npm run dev
# Visit http://localhost:5173 and test your codeTesting on Preview URL โ
Feature branches auto-deploy to preview URLs:
https://feature-api-endpoint.lantern-app-dev.pages.devAccess PIN: Same as dev environment (request from team)
Testing in Dev Environment โ
After merging to dev:
https://dev.ourlantern.appFull staging environment with dev Firebase, staging data, etc.
Testing in Production โ
After merging to main:
https://ourlantern.appLive environment โ use real Firebase, real data, and careful QA!
Common Tasks โ
Add a New Team Member to Access โ
- Go to Access โ Applications
- Click the app (e.g.,
lantern-app-dev) - Click Edit โ Policies
- Edit the PIN or email policy
- Add their email address
- Save
Disable Access Temporarily โ
โ ๏ธ Warning: This makes your site public. Use with caution.
- Go to Access โ Applications
- Click app โ Edit
- Click the Delete button at the bottom
- Confirm deletion
- The domain becomes public (no more Access protection)
To re-enable: Create a new Access app with the same domain and policy.
Monitor Access Logs โ
- Go to Access โ Logs
- View recent authentication attempts
- Filter by domain, date range, or user
- Useful for debugging access issues
Set Different PIN for Different Environments โ
Currently all use the same PIN. To differentiate:
- Edit dev Access app โ Click policy
- Change PIN code
- Save
Now dev has a different PIN than prod (useful for separating access).
Security Best Practices โ
โ Do โ
- โ Keep Access enabled on all non-local environments
- โ Use strong, random PIN codes
- โ Limit who has access to production
- โ Review Access logs regularly
- โ Test new subdomains on preview before production
- โ Use the wildcard app for automatic protection
โ Don't โ
- โ Share PIN codes publicly or in code
- โ Disable Access on production without a reason
- โ Use weak PIN codes (like "1234")
- โ Forget to add DNS records for new subdomains
- โ Commit environment secrets to Git
Troubleshooting โ
New Subdomain Not Working โ
Error: 404 or "Not Found"
Checks:
- Is the DNS record created? Go to DNS tab and verify CNAME exists
- Is it proxied (orange cloud)? If not, enable proxying
- Did you wait for DNS propagation? (Usually instant, but can take 5 mins)
- Is the code actually deployed to the right Pages project?
Fix:
# Verify DNS record
nslookup api.ourlantern.app
# Should resolve to lantern-app.pages.dev or lantern-app-dev.pages.devAccess Redirecting to Wrong Domain โ
Error: dev.ourlantern.app redirects to ourlantern.app
Cause: Multiple Access apps covering the same domain
Fix:
- Go to Access โ Applications
- Check for duplicate entries
- Ensure each domain has only ONE app
- Delete duplicates if found
PIN Not Working โ
Error: "Invalid PIN" even though you entered it correctly
Cause: PIN sent to your email may have expired (usually 15 mins)
Fix:
- Go back and request a new PIN
- Check spam/junk folder
- If still issues, contact admin to reset
Related Documentation โ
- DEPLOYMENT.md โ Main deployment guide
- ENVIRONMENT_SETUP.md โ Setting up environments
- PWA.md โ Progressive Web App setup