Vercel Deployment
Vercel เป็นแพลตฟอร์มสำหรับ Frontend Deployment ที่มาพร้อมกับฟีเจอร์ที่ช่วยให้การ deploy เว็บไซต์เป็นเรื่องง่าย
การเริ่มต้นใช้งาน
1. สมัครและตั้งค่า Vercel
- ไปที่
Vercel Dashboard
- สมัครสมาชิกด้วย GitHub account
- เชื่อมต่อกับ GitHub repository
2. Deploy Project
มีสองวิธีในการ Deploy:
วิธีที่ 1: Deploy ผ่าน Dashboard
- คลิก "Import Project"
- เลือก Git Repository
- กำหนดค่าต่างๆ:
- Project name
- Framework preset
- Build settings
- คลิก "Deploy"
วิธีที่ 2: Deploy ด้วย CLI
- ติดตั้ง Vercel CLI:
bash
npm i -g vercel
bash
pnpm add -g vercel
bash
yarn global add vercel
- Login และ Deploy:
bash
vercel login
vercel
การตั้งค่าที่สำคัญ
Environment Variables
- ไปที่ Project Settings > Environment Variables
- เพิ่ม variables ที่ต้องการ:
- Development
- Preview
- Production
Custom Domains
- ไปที่ Project Settings > Domains
- เพิ่ม domain ของคุณ
- ตั้งค่า DNS records ตามที่ Vercel แนะนำ
Build & Development Settings
json
{
"builds": [
{
"src": "package.json",
"use": "@vercel/static-build"
}
]
}
การใช้งานขั้นสูง
Serverless Functions
typescript
// api/hello.ts
export default function handler(req, res) {
res.status(200).json({ message: 'Hello from Vercel!' })
}
Edge Functions
typescript
export default function middleware(req) {
return new Response('Hello from the edge!')
}
Automatic HTTPS
Vercel จัดการ SSL/TLS certificates ให้อัตโนมัติ:
- Auto-renewal
- Let's Encrypt integration
- Custom certificates support
การ Monitor และ Analytics
1. Real-time Metrics
- Response times
- Error rates
- Deployment status
2. Logs
- Build logs
- Function logs
- Edge logs
Best Practices
Performance Optimization
- ใช้ Image Optimization
- เปิดใช้งาน Edge Caching
- ตั้งค่า Cache-Control headers
Security
- ตั้งค่า Environment Variables อย่างเหมาะสม
- ใช้ Security Headers
- เปิดใช้งาน 2FA
Deployment
- ใช้ Preview Deployments
- ตั้งค่า Git Integration
- ทำ Automated testing
Troubleshooting
ปัญหาที่พบบ่อย
Build Failures
- ตรวจสอบ build logs
- ตรวจสอบ dependencies
- ตรวจสอบ build command
Performance Issues
- ใช้ Vercel Analytics
- ตรวจสอบ Edge Network
- ตั้งค่า caching
Domain Configuration
- ตรวจสอบ DNS records
- รอ DNS propagation
- ตรวจสอบ SSL certificates