4.7 KiB
Les 16: Deployment & Production
Hoofdstuk
Hoofdstuk 3: Advanced (Les 10-18)
Beschrijving
Deploy je eindproject naar productie. Leer environment variables, Vercel deployment, en basis performance optimalisatie.
Te Behandelen
Vercel Deployment Flow
Hoe Vercel werkt:
- Connect GitHub repository
- Push naar main → automatische deploy
- Push naar andere branch → preview URL
- Alles automatisch (build, SSL, CDN)
Waarom Vercel voor Next.js:
- Gemaakt door dezelfde makers
- Zero-config deployment
- Gratis tier ruim voldoende
- Automatische HTTPS
- Global CDN
Environment Variables in Vercel
Lokaal (.env.local) vs Productie (Vercel Dashboard):
| Waar | Bestand/Locatie | Voorbeeld |
|---|---|---|
| Lokaal | .env.local |
Development |
| Vercel | Dashboard → Settings → Env Vars | Production |
Stap voor stap:
- Ga naar je Vercel project
- Settings → Environment Variables
- Voeg toe:
NEXT_PUBLIC_SUPABASE_URLNEXT_PUBLIC_SUPABASE_ANON_KEYOPENAI_API_KEY
- Selecteer environment (Production, Preview, Development)
- Save & Redeploy
Let op:
NEXT_PUBLIC_prefix = zichtbaar in browser- Zonder prefix = alleen server-side (API routes)
Supabase Productie Setup
Redirect URLs configureren:
- Ga naar Supabase → Authentication → URL Configuration
- Voeg toe bij "Redirect URLs":
https://jouw-app.vercel.app/**https://jouw-app.vercel.app
Waarom:
- Auth redirects werken alleen naar toegestane URLs
- Wildcards (
**) voor sub-routes
Deployment Checklist
Voor deployment:
npm run buildwerkt lokaal- Geen TypeScript errors
- Environment variables gedocumenteerd in
.env.example .gitignorebevat.env*.local- README up-to-date
Na deployment:
- App laadt correct
- Auth werkt (login/logout)
- Data wordt opgehaald uit Supabase
- AI features werken (indien van toepassing)
- Geen console errors
Performance Basics
Lighthouse Audit:
- Open Chrome DevTools
- Tab "Lighthouse"
- Klik "Analyze page load"
- Aim for score >80 in elke categorie
Quick wins:
- Gebruik Next.js
Imagecomponent (niet<img>) - Lazy load components die niet direct nodig zijn
- Verwijder ongebruikte dependencies
Security Checklist
Belangrijk voor productie:
- API keys nooit in client-side code
- Supabase RLS enabled (Row Level Security)
- Error messages geven geen gevoelige info
- HTTPS (automatisch via Vercel)
Monitoring Basics
Vercel Dashboard toont:
- Deployments history
- Function logs
- Analytics (optioneel)
Supabase Dashboard toont:
- Database usage
- Auth logs
- API requests
Tools
- Vercel
- GitHub
- Supabase
- Chrome DevTools (Lighthouse)
Lesopdracht (2 uur)
Deploy Je Eindproject
Deel 1: Pre-Deployment Check (30 min)
Run door de checklist:
npm run build- fix eventuele errors- Check TypeScript errors
- Maak/update
.env.example - Update README met project info
Deel 2: Vercel Deployment (30 min)
- Ga naar vercel.com
- "Add New Project"
- Import je GitHub repository
- Voeg environment variables toe
- Deploy!
Deel 3: Supabase Config (20 min)
- Voeg Vercel URL toe aan Supabase redirect URLs
- Test auth in productie
- Verifieer data access
Deel 4: Testing & Lighthouse (40 min)
- Test alle features in productie:
- Login/logout
- CRUD operaties
- AI chat (indien aanwezig)
- Run Lighthouse audit
- Fix issues tot score >80
- Screenshot resultaat
Deliverable
- Werkende productie URL
- Lighthouse screenshot (score >80)
- Test rapport: wat werkt, wat niet
Huiswerk (2 uur)
Polish & Documentatie
Deel 1: Bug Fixes (1 uur)
- Test je app grondig in productie
- Fix gevonden bugs
- Test edge cases:
- Lege states
- Error states
- Loading states
- Redeploy
Deel 2: Performance Optimization (30 min)
- Run Lighthouse opnieuw
- Fix top 3 performance issues
- Document wat je hebt verbeterd
Deel 3: Documentatie Afronden (30 min)
Update je README.md:
- Werkende productie URL
- Features lijst
- Tech stack
- Setup instructies
- Screenshots
Update docs/:
- PROMPT-LOG.md (minimaal 10 entries)
- AI-DECISIONS.md (minimaal 5 entries)
Deliverable
- Geoptimaliseerde productie app
- Complete documentatie
- Lighthouse score >85
Leerdoelen
Na deze les kan de student:
- Een Next.js app deployen naar Vercel
- Environment variables configureren in Vercel
- Supabase redirect URLs instellen voor productie
- Een deployment checklist doorlopen
- Lighthouse gebruiken voor performance audit
- Basis security checks uitvoeren
- Productie monitoring begrijpen