#!/bin/bash # Simple Production Deployment for Redirect Intelligence v2 set -e echo "🚀 Starting Simple Redirect Intelligence v2 Deployment..." # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color print_status() { echo -e "${BLUE}[INFO]${NC} $1" } print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } # Stop any existing processes print_status "Stopping existing processes..." pkill -f "node.*dist/index.js" || true pkill -f "vite" || true # Build the application print_status "Building application..." npm run build print_success "Build completed!" # Set production environment variables export NODE_ENV=production export PORT=3333 export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/redirect_intelligence" export REDIS_URL="redis://localhost:6379" export JWT_SECRET="syiIpEqLvhXjbpyC2+VccCMfhz6rznIObRdZMfqf7Hg=" export CORS_ORIGIN="https://urltrackertools.com" print_status "Starting API server..." # Start API server in background cd apps/api nohup node dist/index.js > ../../api.log 2>&1 & API_PID=$! cd ../.. print_status "API server started with PID: $API_PID" # Wait for API to start sleep 5 # Check if API is running if curl -s http://localhost:3333/health > /dev/null; then print_success "API server is running on http://localhost:3333" else print_warning "API server may not be fully ready yet. Check logs: tail -f api.log" fi # Build and serve frontend print_status "Starting frontend server..." cd apps/web # Update API URL for production export VITE_API_URL="https://urltrackertools.com" # Rebuild with production API URL npm run build # Serve the frontend using a simple HTTP server nohup npx serve -s dist -l 3000 > ../../frontend.log 2>&1 & FRONTEND_PID=$! cd ../.. print_status "Frontend server started with PID: $FRONTEND_PID" # Save PIDs for later management echo $API_PID > api.pid echo $FRONTEND_PID > frontend.pid print_success "Deployment completed successfully!" echo "" echo "🎉 Redirect Intelligence v2 is now running!" echo "" echo "Services:" echo " 🌐 Frontend: http://localhost:3000" echo " 🔗 API: http://localhost:3333" echo " 📊 Health Check: http://localhost:3333/health" echo "" echo "Process IDs:" echo " API: $API_PID (saved to api.pid)" echo " Frontend: $FRONTEND_PID (saved to frontend.pid)" echo "" echo "Logs:" echo " API: tail -f api.log" echo " Frontend: tail -f frontend.log" echo "" echo "To stop services:" echo " kill \$(cat api.pid frontend.pid)" echo "" # Show running status print_status "Testing services..." sleep 2 if curl -s http://localhost:3333/health | grep -q "healthy"; then print_success "✅ API server is healthy" else print_warning "⚠️ API server health check failed" fi if curl -s -I http://localhost:3000 | grep -q "200 OK"; then print_success "✅ Frontend server is running" else print_warning "⚠️ Frontend server may not be ready" fi print_success "🚀 Your application is live!" print_status "Update your nginx proxy to point to these services."