Template Shopify app su dung React Router v7 va PostgreSQL database.
Mo Terminal (tim trong Launchpad hoac nhan Cmd + Space go "Terminal"), dan lenh sau va nhan Enter:
curl -fsSL https://raw.githubusercontent.com/sellersmith/shopify-app-template-react-router-postgres/main/setup.sh | bashScript se tu dong cai tat ca nhung gi can thiet: Homebrew, Git, Node.js, Shopify CLI, va project.
Tao file .env tu file mau:
cd ~/projects/shopify-app-template-react-router-postgres
cp .env.example .envMo file .env va dien connection string PostgreSQL cua ban:
DATABASE_URL=postgresql://user:password@localhost:5432/shopify_app
Mot so dich vu PostgreSQL mien phi:
- Neon: https://neon.tech/ (recommend, free tier tot)
- Supabase: https://supabase.com/
- Local: Cai PostgreSQL qua Homebrew:
brew install postgresql@16 && brew services start postgresql@16
Sau do chay migration:
npx prisma migrate deployshopify auth loginTrinh duyet se mo ra, dang nhap bang tai khoan Shopify Partner cua ban. Chua co? Dang ky tai: https://partners.shopify.com/
npm run devShopify CLI se hoi ban chon app va dev store. Chon theo huong dan tren man hinh.
Sau khi chay xong, nhan P de mo app trong trinh duyet. Click Install de cai app vao dev store.
Xong! App cua ban da chay. Moi thay doi trong code se tu dong cap nhat tren trinh duyet.
app/
routes/
app.tsx # Layout chinh (sidebar, navigation)
app._index.tsx # Trang Dashboard
app.additional.tsx # Trang phu
auth.$.tsx # OAuth callback
auth.login/ # Trang dang nhap
webhooks.app.*.tsx # Xu ly webhook
shopify.server.ts # Cau hinh Shopify app
db.server.ts # Ket noi database
prisma/
schema.prisma # Database schema (PostgreSQL)
migrations/ # Database migrations
extensions/ # Shopify extensions
.env.example # Mau file cau hinh
| Lenh | Mo ta |
|---|---|
npm run dev |
Chay app trong che do dev |
npm run build |
Build app cho production |
npm run lint |
Kiem tra loi code |
npm run typecheck |
Kiem tra loi TypeScript |
npx prisma studio |
Mo trinh duyet database |
npx prisma migrate deploy |
Chay migration database |
npx prisma migrate dev |
Tao migration moi khi thay doi schema |
Template nay su dung PostgreSQL — can cau hinh connection string trong file .env.
Khi thay doi schema (prisma/schema.prisma), chay npx prisma migrate dev de tao migration moi.
- Navigation: Dung
Linktureact-router, khong dung<a> - GraphQL: Dung
admin.graphql()de truy van du lieu Shopify - Webhooks: Khai bao trong
shopify.app.toml, khong dang ky trong code - Khong commit file
.env— file nay chua thong tin bi mat
Kiem tra DATABASE_URL trong file .env co dung khong. Dam bao:
- PostgreSQL dang chay (local:
brew services list) - Username, password, database name dung
- Neu dung Neon/Supabase: kiem tra connection string tu dashboard
npx prisma migrate deployKiem tra Terminal co dang chay npm run dev khong. Thu tat va chay lai.
Kiem tra dong ho may tinh da bat "Set time and date automatically" chua (System Settings > Date & Time).