- Added complete Next.js frontend with responsive design - Added NestJS backend with PostgreSQL and Redis - Added comprehensive VPS deployment script (vps-deploy.sh) - Added deployment guide and documentation - Added all assets and static files - Configured SSL, Nginx, PM2, and monitoring - Ready for production deployment on any VPS
256 lines
7.5 KiB
Bash
Executable File
256 lines
7.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# 🚗 Smart Parking Finder - Unified Start Script
|
|
# This script provides multiple deployment options
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
CYAN='\033[0;36m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Project directory (go back one level since we're in scripts folder)
|
|
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
|
|
# Function to display menu
|
|
show_menu() {
|
|
echo -e "${BLUE}🚗 Smart Parking Finder - Start Options${NC}"
|
|
echo -e "${BLUE}============================================${NC}"
|
|
echo ""
|
|
echo -e "${GREEN}1.${NC} 🎨 Frontend Only (Quick Demo)"
|
|
echo -e "${GREEN}2.${NC} 🌐 Network Access (Other devices can access)"
|
|
echo -e "${GREEN}3.${NC} 🌍 Global Access (Internet access via ngrok)"
|
|
echo -e "${GREEN}4.${NC} 🔄 Full Development (Frontend + Backend)"
|
|
echo -e "${GREEN}5.${NC} 🐳 Docker Development (Complete with services)"
|
|
echo -e "${GREEN}6.${NC} ❌ Exit"
|
|
echo ""
|
|
echo -e "${YELLOW}Choose an option [1-6]:${NC} "
|
|
}
|
|
|
|
# Function to check if command exists
|
|
command_exists() {
|
|
command -v "$1" >/dev/null 2>&1
|
|
}
|
|
|
|
# Function to get local IP
|
|
get_local_ip() {
|
|
ifconfig | grep -E "inet.*broadcast" | head -1 | awk '{print $2}'
|
|
}
|
|
|
|
# Function to start frontend only
|
|
start_frontend_only() {
|
|
echo -e "${BLUE}🎨 Starting Frontend Only...${NC}"
|
|
cd "$PROJECT_DIR/frontend"
|
|
|
|
if [ ! -d "node_modules" ]; then
|
|
echo -e "${YELLOW}📦 Installing dependencies...${NC}"
|
|
npm install
|
|
fi
|
|
|
|
echo -e "${GREEN}🚀 Starting Next.js development server...${NC}"
|
|
echo -e "${CYAN}🌐 Frontend will run on: http://localhost:3000${NC}"
|
|
echo ""
|
|
echo -e "${YELLOW}⚠️ Note: Backend is not started. Some features may not work.${NC}"
|
|
echo -e "${YELLOW}💡 To start backend, open new terminal and run:${NC}"
|
|
echo -e "${YELLOW} cd backend && npm run start:dev${NC}"
|
|
echo ""
|
|
|
|
npm run dev
|
|
}
|
|
|
|
# Function to start with network access
|
|
start_network_access() {
|
|
echo -e "${BLUE}🌐 Starting with Network Access...${NC}"
|
|
LOCAL_IP=$(get_local_ip)
|
|
|
|
echo -e "${BLUE}===============================================${NC}"
|
|
echo -e "${BLUE}🌐 NETWORK ACCESS INFORMATION${NC}"
|
|
echo -e "${BLUE}===============================================${NC}"
|
|
echo -e "${GREEN}📱 Local Access: http://localhost:3000${NC}"
|
|
echo -e "${GREEN}🌍 Network Access: http://$LOCAL_IP:3000${NC}"
|
|
echo -e "${BLUE}===============================================${NC}"
|
|
echo ""
|
|
echo -e "${YELLOW}📋 To access from other devices:${NC}"
|
|
echo -e "${YELLOW} 1. Make sure devices are on the same WiFi network${NC}"
|
|
echo -e "${YELLOW} 2. Use this URL: http://$LOCAL_IP:3000${NC}"
|
|
echo -e "${YELLOW} 3. Make sure macOS Firewall allows Node.js connections${NC}"
|
|
echo ""
|
|
|
|
cd "$PROJECT_DIR/frontend"
|
|
|
|
if [ ! -d "node_modules" ]; then
|
|
echo -e "${YELLOW}📦 Installing dependencies...${NC}"
|
|
npm install
|
|
fi
|
|
|
|
npm run dev
|
|
}
|
|
|
|
# Function to start with global access
|
|
start_global_access() {
|
|
echo -e "${BLUE}🌍 Starting with Global Access...${NC}"
|
|
|
|
if ! command_exists ngrok; then
|
|
echo -e "${YELLOW}❌ ngrok is not installed. Installing...${NC}"
|
|
if command_exists brew; then
|
|
brew install ngrok/ngrok/ngrok
|
|
else
|
|
echo -e "${RED}❌ Please install ngrok manually: https://ngrok.com/download${NC}"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
LOCAL_IP=$(get_local_ip)
|
|
|
|
echo -e "${BLUE}===============================================${NC}"
|
|
echo -e "${BLUE}🌍 GLOBAL ACCESS DEPLOYMENT${NC}"
|
|
echo -e "${BLUE}===============================================${NC}"
|
|
echo -e "${GREEN}📱 Local Access: http://localhost:3000${NC}"
|
|
echo -e "${GREEN}🏠 Network Access: http://$LOCAL_IP:3000${NC}"
|
|
echo -e "${GREEN}🌐 Global Access: Will be shown after ngrok starts${NC}"
|
|
echo -e "${BLUE}===============================================${NC}"
|
|
echo ""
|
|
|
|
cd "$PROJECT_DIR/frontend"
|
|
|
|
if [ ! -d "node_modules" ]; then
|
|
echo -e "${YELLOW}📦 Installing dependencies...${NC}"
|
|
npm install
|
|
fi
|
|
|
|
# Start frontend in background
|
|
npm run dev &
|
|
FRONTEND_PID=$!
|
|
|
|
# Wait for frontend to start
|
|
sleep 5
|
|
|
|
# Start ngrok
|
|
echo -e "${CYAN}🔗 Creating global tunnel...${NC}"
|
|
ngrok http 3000
|
|
|
|
# Cleanup on exit
|
|
trap "kill $FRONTEND_PID" EXIT
|
|
}
|
|
|
|
# Function to start full development
|
|
start_full_development() {
|
|
echo -e "${BLUE}🔄 Starting Full Development (Frontend + Backend)...${NC}"
|
|
|
|
# Check Node.js
|
|
if ! command_exists node; then
|
|
echo -e "${RED}❌ Node.js is not installed. Please install Node.js first.${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}✅ Node.js is ready${NC}"
|
|
|
|
# Start backend in background
|
|
echo -e "${BLUE}🔧 Starting Backend on http://localhost:3001...${NC}"
|
|
cd "$PROJECT_DIR/backend"
|
|
|
|
if [ ! -d "node_modules" ]; then
|
|
echo -e "${YELLOW}📦 Installing backend dependencies...${NC}"
|
|
npm install
|
|
fi
|
|
|
|
npm run start:dev &
|
|
BACKEND_PID=$!
|
|
|
|
# Start frontend
|
|
echo -e "${BLUE}🎨 Starting Frontend on http://localhost:3000...${NC}"
|
|
cd "$PROJECT_DIR/frontend"
|
|
|
|
if [ ! -d "node_modules" ]; then
|
|
echo -e "${YELLOW}📦 Installing frontend dependencies...${NC}"
|
|
npm install
|
|
fi
|
|
|
|
# Wait a bit for backend to start
|
|
sleep 3
|
|
|
|
npm run dev &
|
|
FRONTEND_PID=$!
|
|
|
|
echo -e "${GREEN}🎉 Full development environment started!${NC}"
|
|
echo -e "${GREEN}Frontend: http://localhost:3000${NC}"
|
|
echo -e "${GREEN}Backend: http://localhost:3001${NC}"
|
|
|
|
# Wait for user to exit
|
|
echo -e "${YELLOW}Press Ctrl+C to stop all services...${NC}"
|
|
|
|
# Cleanup on exit
|
|
trap "kill $BACKEND_PID $FRONTEND_PID 2>/dev/null" EXIT
|
|
wait
|
|
}
|
|
|
|
# Function to start docker development
|
|
start_docker_development() {
|
|
echo -e "${BLUE}🐳 Starting Docker Development...${NC}"
|
|
|
|
# Check Docker
|
|
if ! command_exists docker; then
|
|
echo -e "${RED}❌ Docker is not installed. Please install Docker first.${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
if ! docker info >/dev/null 2>&1; then
|
|
echo -e "${RED}❌ Docker is not running. Please start Docker and try again.${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}✅ Docker is ready${NC}"
|
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
echo -e "${BLUE}🚀 Starting Docker Compose...${NC}"
|
|
docker-compose up -d
|
|
|
|
echo -e "${GREEN}🎉 Docker development environment started!${NC}"
|
|
echo -e "${GREEN}Frontend: http://localhost:3000${NC}"
|
|
echo -e "${GREEN}Backend: http://localhost:3001${NC}"
|
|
echo -e "${GREEN}Database: localhost:5432${NC}"
|
|
echo -e "${GREEN}Redis: localhost:6379${NC}"
|
|
|
|
echo -e "${YELLOW}To stop: docker-compose down${NC}"
|
|
}
|
|
|
|
# Main execution
|
|
while true; do
|
|
show_menu
|
|
read -p "" choice
|
|
|
|
case $choice in
|
|
1)
|
|
start_frontend_only
|
|
break
|
|
;;
|
|
2)
|
|
start_network_access
|
|
break
|
|
;;
|
|
3)
|
|
start_global_access
|
|
break
|
|
;;
|
|
4)
|
|
start_full_development
|
|
break
|
|
;;
|
|
5)
|
|
start_docker_development
|
|
break
|
|
;;
|
|
6)
|
|
echo -e "${GREEN}👋 Goodbye!${NC}"
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo -e "${RED}❌ Invalid option. Please choose 1-6.${NC}"
|
|
echo ""
|
|
;;
|
|
esac
|
|
done
|