Cài đặt

Hướng dẫn cài đặt từ đầu đến production deploy

Cài đặt

Hướng dẫn đầy đủ từ git clone đến khi https://dung87.io.vn/ chạy trên Cloudflare Pages.

1. Prerequisites

ToolVersionCài đặt
Node.js≥ 20https://nodejs.org (LTS) hoặc nvm install 20
npm≥ 10Kèm theo Node
Git≥ 2.30https://git-scm.com
GitHub accounthttps://github.com/signup
Cloudflare accountFree tier OKhttps://dash.cloudflare.com/sign-up
Domain dung87.io.vnTrỏ về Cloudflare NShttps://dash.cloudflare.com → Add site

2. Quick start (5 phút)

# 1. Clone
git clone git@github.com:vuhuudung/dung87.io.vn.git
cd dung87.io.vn

# 2. Install
npm install

# 3. Dev server
npm run dev
# → http://localhost:4321

# 4. Validate
npm run validate
npm run lint

# 5. Production build
npm run build
npm run preview
# → http://localhost:4322

3. Cấu hình Cloudflare Pages

Bước 1: Verify domain

dig NS dung87.io.vn
# Expect: cortney.ns.cloudflare.com, lynn.ns.cloudflare.com

Bước 2: Tạo Pages project

  1. Cloudflare Dashboard → Workers & PagesCreate application
  2. Tab PagesConnect to Git
  3. Authorize GitHub → chọn vuhuudung/dung87.io.vn
  4. Project name: dung87-io-vn-hub
  5. Production branch: main
  6. Build settings:
    • Build command: npm run build
    • Build output directory: dist
    • Root directory: (trống)
  7. Environment variables: NODE_VERSION = 20

Bước 3: Add custom domains

Pages project → Custom domainsSet up a custom domain:

  • Thêm dung87.io.vn (apex)
  • Thêm www.dung87.io.vn

Cloudflare tự động issue SSL cert (~30-90 giây).

4. GitHub Actions secrets

Vào Settings → Secrets and variables → Actions → New repository secret:

NameValueCách lấy
CLOUDFLARE_API_TOKENToken có scope Pages:Edit + Account:Readhttps://dash.cloudflare.com/profile/api-tokens
CLOUDFLARE_ACCOUNT_IDAccount ID của bạnURL ?to=/:account/... trong CF dashboard

5. Verify

# DNS
dig CNAME dung87.io.vn
# Expect: <project>.pages.dev

# HTTPS
curl -sI https://dung87.io.vn/ | head -1
# Expect: HTTP/2 200

Mở https://dung87.io.vn/ — site hiển thị hero + 4 project cards + skill filter.

Troubleshooting nhanh

Vấn đềFix
EACCES khi npm installDùng nvm hoặc sudo chown -R $(whoami) ~/.npm
Port 4321 đã dùngnpx kill-port 4321 hoặc taskkill /PID <pid> /F (Win)
validate fail: Invalid slugSửa slug match /^[a-z0-9-]+$/ (lowercase + a-z, 0-9, -)
GH Actions: Authentication errorMint token mới, kiểm tra secret name đúng (case-sensitive)
Site trả HTML cũdig CNAME dung87.io.vn xem DNS, hard reload browser
Custom domain “pending” foreverCheck DNS, đợi 5-10 phút cho cert
/en/ 308 redirectĐây là behavior chuẩn của CF Pages, browser tự follow

Chi tiết troubleshooting: xem SETUP.md trên GitHub.

Next steps