#!/bin/bash
# Server-side deploy for cPanel/dedicated host (git + PM2 on port 8001).
# Run from the app directory on the server: ./deploy.sh
# Requires: .env present in this directory (never committed).
set -e
cd "$(dirname "$0")"

echo "➡️ Pulling latest code..."
git pull origin main

echo "➡️ Installing dependencies..."
npm install

echo "➡️ Building project with Webpack..."
npx next build --webpack

echo "➡️ Restarting PM2 app on port 8001..."
PORT=8001 npx pm2 restart heavyhaulgbt-app --update-env || PORT=8001 npx pm2 start npm --name "heavyhaulgbt-app" -- start -- -p 8001

echo "✅ Deployment complete and app is running!"
