From 14890b68750c9c6133008af562d0c59ed78fa283 Mon Sep 17 00:00:00 2001 From: ImGKTZ27 Date: Sun, 22 Feb 2026 03:05:15 +0500 Subject: [PATCH] feat: update deployment scripts and README for improved setup and configuration --- .gitignore | 4 +- .postgres-env | 5 ++ README.md | 86 +++++++++++++++++++++++++--------- deploy.sh | 118 +++++++++++++++++++++++++++++++++++++++++++++++ update-domain.sh | 43 +++++++++++++++++ 5 files changed, 234 insertions(+), 22 deletions(-) create mode 100644 .postgres-env create mode 100644 deploy.sh create mode 100644 update-domain.sh diff --git a/.gitignore b/.gitignore index 5ef6a52..0a0294e 100644 --- a/.gitignore +++ b/.gitignore @@ -30,8 +30,10 @@ yarn-debug.log* yarn-error.log* .pnpm-debug.log* -# env files (can opt-in for committing if needed) +# env files .env* +!.env.local.example +!.postgres-env.example # vercel .vercel diff --git a/.postgres-env b/.postgres-env new file mode 100644 index 0000000..364b21d --- /dev/null +++ b/.postgres-env @@ -0,0 +1,5 @@ +DB_USER=postgres +DB_PASS=your_password_here +DB_HOST=192.168.2.175 +DB_PORT=5432 +DB_NAME=fairreview diff --git a/README.md b/README.md index e215bc4..290de3c 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,80 @@ -This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app). +# FairReview - Steam Game Review Platform -## Getting Started +A gaming-focused website for reviewing Steam games with Steam account integration. -First, run the development server: +## Features +- **Public Access**: Browse games, read reviews +- **Website Account**: Register/login with email, upvote/downvote reviews +- **Steam Integration**: Link Steam account to post reviews with playtime & achievements displayed + +## Tech Stack + +- Next.js 14 (App Router) +- PostgreSQL (your existing DB at 192.168.2.175:5432) +- NextAuth.js with Credentials + Steam OpenID +- Tailwind CSS (gaming dark theme) + +## Quick Deploy + +### 1. Upload to Linux Server + +Clone this repo to your Linux server. + +### 2. Configure Database Credentials + +Edit `.postgres-env`: ```bash -npm run dev -# or -yarn dev -# or -pnpm dev -# or -bun dev +DB_USER=postgres +DB_PASS=your_actual_password +DB_HOST=192.168.2.175 +DB_PORT=5432 +DB_NAME=fairreview ``` -Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. +### 3. Run Deployment -You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. +```bash +chmod +x deploy.sh +./deploy.sh 192.168.2.175:3000 +``` -This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel. +### 4. Update Steam API Key -## Learn More +After deployment, edit `.env.local` and add your Steam Web API key: +``` +STEAM_API_KEY=your_steam_api_key +``` -To learn more about Next.js, take a look at the following resources: +Then restart: +```bash +pm2 restart fairreview +``` -- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. -- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. +## Changing Domain Later -You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome! +```bash +./update-domain.sh fairreview.example.com +``` -## Deploy on Vercel +## Useful Commands -The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. +```bash +pm2 status # Check app status +pm2 logs # View logs +pm2 restart fairreview # Restart app +``` -Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details. +## Project Structure + +``` +├── src/ +│ ├── app/ # Next.js pages & API routes +│ ├── components/ # UI components +│ └── lib/ # Utilities (db, auth, steam) +├── prisma/ +│ └── schema.prisma # Database schema +├── deploy.sh # Main deployment script +├── update-domain.sh # Domain update script +└── .postgres-env # DB credentials (you edit this) +``` diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..08c6b42 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,118 @@ +#!/bin/bash +set -e + +DOMAIN="${1:-192.168.2.175:3000}" + +echo "=== FairReview Deployment Script ===" +echo "Target domain: $DOMAIN" +echo "" + +# Check if running as root or with sudo +if [ "$EUID" -eq 0 ]; then + echo "Warning: Running as root is not recommended. Use a regular user with sudo." + echo "" +fi + +# Load database credentials +if [ ! -f .postgres-env ]; then + echo "Error: .postgres-env file not found!" + echo "Please create .postgres-env with your database credentials." + exit 1 +fi + +source .postgres-env + +# Validate credentials +if [ -z "$DB_PASS" ] || [ "$DB_PASS" = "your_password_here" ]; then + echo "Error: Please update .postgres-env with your actual database password." + exit 1 +fi + +echo "Database configuration:" +echo " Host: $DB_HOST:$DB_PORT" +echo " Database: $DB_NAME" +echo " User: $DB_USER" +echo "" + +# Install Node.js 18.x +echo "=== Installing Node.js 18.x ===" +if ! command -v node &> /dev/null; then + curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - + sudo apt install -y nodejs +else + echo "Node.js already installed: $(node --version)" +fi + +# Install required packages +echo "" +echo "=== Installing required packages ===" +sudo apt update +sudo apt install -y curl build-essential git + +# Install PM2 globally +echo "" +echo "=== Installing PM2 ===" +if ! command -v pm2 &> /dev/null; then + sudo npm install -g pm2 +else + echo "PM2 already installed: $(pm2 --version)" +fi + +# Install npm dependencies +echo "" +echo "=== Installing npm dependencies ===" +npm install +npm install next-auth@beta @prisma/client bcryptjs +npm install -D prisma @types/bcryptjs + +# Create .env.local +echo "" +echo "=== Creating environment configuration ===" +NEXTAUTH_SECRET=$(openssl rand -base64 32) +cat > .env.local << EOF +DATABASE_URL="postgresql://${DB_USER}:${DB_PASS}@${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=require" +NEXTAUTH_SECRET="${NEXTAUTH_SECRET}" +NEXTAUTH_URL="http://${DOMAIN}" +STEAM_API_KEY="YOUR_STEAM_WEB_API_KEY" +EOF + +echo "Environment file created: .env.local" +echo " NEXTAUTH_URL: http://${DOMAIN}" +echo " Database: ${DB_HOST}:${DB_PORT}/${DB_NAME}" +echo "" +echo "IMPORTANT: Update STEAM_API_KEY in .env.local with your Steam Web API key!" + +# Generate Prisma client and push schema +echo "" +echo "=== Setting up database ===" +npx prisma generate +npx prisma db push + +# Build for production +echo "" +echo "=== Building for production ===" +npm run build + +# Configure PM2 +echo "" +echo "=== Starting application with PM2 ===" +pm2 stop fairreview 2>/dev/null || true +pm2 delete fairreview 2>/dev/null || true +pm2 start npm --name "fairreview" -- run start + +# Save PM2 config for restart on reboot +pm2 save + +# Setup PM2 startup (if systemd is available) +if command -v systemctl &> /dev/null; then + sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u $USER --hp $HOME 2>/dev/null || true +fi + +echo "" +echo "=== Deployment Complete ===" +echo "Application running at: http://${DOMAIN}" +echo "" +echo "Useful commands:" +echo " pm2 status - Check application status" +echo " pm2 logs - View application logs" +echo " pm2 restart fairreview - Restart application" diff --git a/update-domain.sh b/update-domain.sh new file mode 100644 index 0000000..3741145 --- /dev/null +++ b/update-domain.sh @@ -0,0 +1,43 @@ +#!/bin/bash +set -e + +if [ -z "$1" ]; then + echo "Usage: ./update-domain.sh " + echo "" + echo "Examples:" + echo " ./update-domain.sh 192.168.2.175:3000" + echo " ./update-domain.sh fairreview.example.com" + exit 1 +fi + +NEW_DOMAIN="$1" + +echo "=== Updating Domain ===" +echo "New domain: $NEW_DOMAIN" + +# Check if .env.local exists +if [ ! -f .env.local ]; then + echo "Error: .env.local not found. Run deploy.sh first." + exit 1 +fi + +# Load database credentials +if [ -f .postgres-env ]; then + source .postgres-env +fi + +# Update NEXTAUTH_URL in .env.local +sed -i "s|NEXTAUTH_URL=.*|NEXTAUTH_URL=\"http://$NEW_DOMAIN\"|" .env.local + +echo "Updated NEXTAUTH_URL in .env.local" + +# Rebuild and restart +echo "Rebuilding application..." +npm run build + +echo "Restarting application..." +pm2 restart fairreview + +echo "" +echo "=== Domain Update Complete ===" +echo "Application running at: http://$NEW_DOMAIN"