feat: add admin API routes for tags, timeline events, uploads, and uses management
Some checks failed
Deploy to VPS / deploy (push) Has been cancelled
Some checks failed
Deploy to VPS / deploy (push) Has been cancelled
- Implemented GET and POST endpoints for managing tags in `src/app/api/admin/tags/route.ts`. - Created PUT and DELETE endpoints for timeline events in `src/app/api/admin/timeline/[id]/route.ts`. - Added GET and POST endpoints for timeline management in `src/app/api/admin/timeline/route.ts`. - Developed file upload functionality with validation in `src/app/api/admin/upload/route.ts`. - Introduced PUT and DELETE endpoints for managing uses items in `src/app/api/admin/uses/[id]/route.ts`. - Added GET and POST endpoints for uses management in `src/app/api/admin/uses/route.ts`. feat: enhance admin UI components for better user experience - Created `AdminSidebar` component for navigation in `src/components/admin/AdminSidebar.tsx`. - Developed `ImageUpload` component for handling image uploads in `src/components/admin/ImageUpload.tsx`. - Implemented `RichTextEditor` component for rich text editing in `src/components/admin/RichTextEditor.tsx`. - Added `TagsInput` component for managing tags in `src/components/admin/TagsInput.tsx`. - Created `TiptapRenderer` component for rendering HTML content in `src/components/writing/TiptapRenderer.tsx`. feat: establish database interaction layer with Prisma - Added database connection and session management in `src/lib/db.ts` and `src/lib/auth.ts`. - Implemented CRUD operations for posts, products, projects, settings, timeline events, and uses items in respective files under `src/lib/db/`. - Introduced utility functions for formatting dates and slug generation in `src/lib/types.ts`.
This commit is contained in:
259
DEPLOY.md
Normal file
259
DEPLOY.md
Normal file
@@ -0,0 +1,259 @@
|
||||
# biztaghavi.com — Deployment Guide
|
||||
|
||||
> Server: `193.105.234.35` (NODE-Cloud, Iran)
|
||||
> Stack: Next.js 16 · MariaDB 11 · Prisma · pnpm · Docker · Nginx
|
||||
> Domain: `biztaghavi.com` (behind ArvanCloud CDN)
|
||||
|
||||
---
|
||||
|
||||
## 0. Pre-flight — do this ONCE on your Mac
|
||||
|
||||
### Download Prisma engine binaries
|
||||
|
||||
Prisma cannot download its binaries on the server (`binaries.prisma.sh` is blocked).
|
||||
Run this on your Mac:
|
||||
|
||||
```bash
|
||||
# Find your exact Prisma version first
|
||||
cat package.json | grep '"prisma"'
|
||||
# e.g. "6.x.x"
|
||||
|
||||
# Download for Alpine Linux (linux-musl-openssl-3.0.x)
|
||||
npx prisma@<version> fetch-engines --version linux-musl-openssl-3.0.x
|
||||
|
||||
# The binaries land in ~/.prisma/engines/ — copy them to the repo
|
||||
mkdir -p prisma-binaries
|
||||
cp ~/.prisma/engines/libquery_engine-linux-musl-openssl-3.0.x.so.node prisma-binaries/
|
||||
cp ~/.prisma/engines/schema-engine-linux-musl-openssl-3.0.x prisma-binaries/
|
||||
|
||||
# Commit them
|
||||
git add prisma-binaries/
|
||||
git commit -m "add prisma engine binaries for linux-musl"
|
||||
```
|
||||
|
||||
> These files are ~50 MB. They must be in git before deployment.
|
||||
|
||||
---
|
||||
|
||||
## 1. First-time server setup
|
||||
|
||||
```bash
|
||||
ssh root@193.105.234.35
|
||||
|
||||
# Create app directory
|
||||
mkdir -p /srv/nodecloud/apps/biztaghavi
|
||||
cd /srv/nodecloud/apps/biztaghavi
|
||||
|
||||
# Clone from Gitea
|
||||
git clone http://git.nodecloud.ir/nodegroup/biztaghavi.git .
|
||||
|
||||
# Create environment file
|
||||
cp .env.example .env
|
||||
nano .env # fill in real values — see section 2
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. Environment variables (`.env`)
|
||||
|
||||
```env
|
||||
DATABASE_URL=mysql://biztaghavi:STRONG_PASSWORD@db:3306/biztaghavi
|
||||
SESSION_SECRET=<64-char random hex — run: openssl rand -hex 32>
|
||||
SETUP_KEY=<secret used once to create admin user>
|
||||
RESEND_API_KEY=<from resend.com — optional>
|
||||
CONTACT_EMAIL=ali@biztaghavi.com
|
||||
NEXT_PUBLIC_SITE_URL=https://biztaghavi.com
|
||||
|
||||
# Docker DB credentials (must match DATABASE_URL above)
|
||||
DB_ROOT_PASSWORD=<strong root password>
|
||||
DB_NAME=biztaghavi
|
||||
DB_USER=biztaghavi
|
||||
DB_PASSWORD=<same as DATABASE_URL password>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. Build & launch
|
||||
|
||||
```bash
|
||||
cd /srv/nodecloud/apps/biztaghavi
|
||||
|
||||
# Build (first time is slow — ~5-10 min due to Liara mirror rate limiting)
|
||||
docker compose build --no-cache
|
||||
|
||||
# Launch
|
||||
docker compose up -d
|
||||
|
||||
# Verify containers are running
|
||||
docker compose ps
|
||||
|
||||
# Check logs
|
||||
docker compose logs -f next-app
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Run database migrations
|
||||
|
||||
Prisma migrations run via direct SQL (not `prisma migrate` — that would need network).
|
||||
|
||||
```bash
|
||||
# Generate migration SQL from schema
|
||||
# (run this on your Mac, then copy the SQL to the server)
|
||||
npx prisma migrate diff \
|
||||
--from-empty \
|
||||
--to-schema-datamodel prisma/schema.prisma \
|
||||
--script > migration.sql
|
||||
|
||||
# Copy SQL to server
|
||||
scp migration.sql root@193.105.234.35:/tmp/
|
||||
|
||||
# Apply on server
|
||||
docker exec -i biztaghavi-db-1 mariadb \
|
||||
-u biztaghavi -p'STRONG_PASSWORD' biztaghavi < /tmp/migration.sql
|
||||
```
|
||||
|
||||
Or use `prisma db push` directly on the container (doesn't require migrations directory):
|
||||
|
||||
```bash
|
||||
docker exec -it biztaghavi-next-app-1 sh -c \
|
||||
"DATABASE_URL=mysql://biztaghavi:STRONG_PASSWORD@db:3306/biztaghavi \
|
||||
npx prisma db push --skip-generate"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Create admin user (one-time)
|
||||
|
||||
After containers are running:
|
||||
|
||||
```bash
|
||||
curl -X POST https://biztaghavi.com/api/admin/setup \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "x-setup-key: YOUR_SETUP_KEY" \
|
||||
-d '{"username":"ali","password":"YOUR_STRONG_PASSWORD"}'
|
||||
```
|
||||
|
||||
Then **remove `SETUP_KEY` from `.env`** and restart the app:
|
||||
|
||||
```bash
|
||||
# Edit .env — delete the SETUP_KEY line
|
||||
docker compose restart next-app
|
||||
```
|
||||
|
||||
Admin panel: `https://biztaghavi.com/admin`
|
||||
|
||||
---
|
||||
|
||||
## 6. Nginx config
|
||||
|
||||
Port: **3009** (next available after 3008 for Khanehban)
|
||||
|
||||
Create `/etc/nginx/sites-available/biztaghavi.com`:
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
listen 443 ssl;
|
||||
listen [::]:443 ssl;
|
||||
server_name biztaghavi.com www.biztaghavi.com;
|
||||
|
||||
ssl_certificate /etc/ssl/certs/nodecloud-selfsigned.crt;
|
||||
ssl_certificate_key /etc/ssl/private/nodecloud-selfsigned.key;
|
||||
|
||||
client_max_body_size 20M;
|
||||
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:3009;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_read_timeout 60;
|
||||
proxy_send_timeout 60;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```bash
|
||||
ln -s /etc/nginx/sites-available/biztaghavi.com /etc/nginx/sites-enabled/
|
||||
nginx -t && nginx -s reload
|
||||
```
|
||||
|
||||
In **ArvanCloud dashboard**: SSL mode = "Full", origin = `193.105.234.35`, purge cache.
|
||||
|
||||
> Port 3009 must match the `ports` binding in `docker-compose.yml` — verify it's `"127.0.0.1:3009:3000"`.
|
||||
|
||||
---
|
||||
|
||||
## 7. Uploaded images volume
|
||||
|
||||
Images uploaded via the admin panel land in `/app/public/uploads/` inside the container.
|
||||
The `uploads` Docker volume keeps them across redeployments.
|
||||
|
||||
To back up uploads manually:
|
||||
```bash
|
||||
docker cp biztaghavi-next-app-1:/app/public/uploads ./uploads-backup/
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 8. Redeployment (after code changes)
|
||||
|
||||
```bash
|
||||
cd /srv/nodecloud/apps/biztaghavi
|
||||
git pull
|
||||
|
||||
# Re-apply Iran Dockerfile is already correct — no extra steps needed
|
||||
docker compose build --no-cache
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
> If Prisma schema changed, re-run the migration SQL step (section 4).
|
||||
|
||||
---
|
||||
|
||||
## 9. Troubleshooting
|
||||
|
||||
| Problem | Fix |
|
||||
|---|---|
|
||||
| Build hangs / 429 from Liara mirror | Wait 15 min, retry. Or transfer `node_modules` from Mac. |
|
||||
| Prisma "engine not found" | Check `prisma-binaries/` has both files and is committed. |
|
||||
| Container starts but site 502 | `docker compose logs -f next-app` — likely DB connection timeout. |
|
||||
| Images not showing | Make sure `uploads` volume is mounted and `client_max_body_size 20M` is in nginx. |
|
||||
| Admin login fails | Double-check `SESSION_SECRET` is 32+ chars and consistent across restarts. |
|
||||
| DB won't start | MariaDB 11 healthcheck takes ~30s on first boot — wait and retry. |
|
||||
|
||||
---
|
||||
|
||||
## 10. Transferring `node_modules` from Mac (fallback if Liara mirror fails)
|
||||
|
||||
```bash
|
||||
# On Mac — install for Linux Alpine
|
||||
npm install \
|
||||
--platform=linux --arch=x64 --libc=musl \
|
||||
--ignore-scripts
|
||||
|
||||
# Also install musl-specific native binaries
|
||||
npm install \
|
||||
@next/swc-linux-x64-musl \
|
||||
lightningcss-linux-x64-musl \
|
||||
@tailwindcss/oxide-linux-x64-musl \
|
||||
--platform=linux --arch=x64 --libc=musl
|
||||
|
||||
# Tar it
|
||||
tar -czf node_modules.tar.gz node_modules/
|
||||
|
||||
# Upload to server
|
||||
scp node_modules.tar.gz root@193.105.234.35:/srv/nodecloud/apps/biztaghavi/
|
||||
|
||||
# On server — extract and build without install
|
||||
tar -xzf node_modules.tar.gz
|
||||
docker compose build --no-cache # Dockerfile will skip pnpm install if node_modules exists
|
||||
```
|
||||
|
||||
> You may need to modify the Dockerfile's `RUN pnpm install` step to skip if `node_modules/` already exists when using this approach.
|
||||
Reference in New Issue
Block a user