119 lines
3.9 KiB
Bash
Executable File
119 lines
3.9 KiB
Bash
Executable File
#!/bin/bash
|
|
# Script to run a development server for the Stones Database application
|
|
|
|
set -e # Exit immediately if a command exits with a non-zero status
|
|
|
|
# Colors for pretty output
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Check for required tools
|
|
echo -e "${YELLOW}Checking for required tools...${NC}"
|
|
|
|
# Check if Node.js is installed
|
|
if ! command -v node &> /dev/null; then
|
|
echo -e "${RED}Error: Node.js is not installed. Please install Node.js first.${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Check Node.js version
|
|
NODE_VERSION=$(node -v | cut -d "v" -f 2 | cut -d "." -f 1)
|
|
if [ "$NODE_VERSION" -lt "16" ]; then
|
|
echo -e "${RED}Error: Node.js version 16 or higher is required. Current version: $(node -v)${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if npm is installed
|
|
if ! command -v npm &> /dev/null; then
|
|
echo -e "${RED}Error: npm is not installed. Please install npm first.${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Print npm and Node.js versions for diagnostic purposes
|
|
echo -e "${YELLOW}Node.js version: $(node -v)${NC}"
|
|
echo -e "${YELLOW}npm version: $(npm -v)${NC}"
|
|
|
|
# Check Next.js version for diagnostic purposes
|
|
echo -e "${YELLOW}Next.js version: $(npm list next | grep next@ | head -1)${NC}"
|
|
|
|
# Check for .env file
|
|
if [ ! -f ".env.local" ] && [ ! -f ".env" ]; then
|
|
echo -e "${YELLOW}Creating .env.local file with development settings...${NC}"
|
|
cat > .env.local << EOF
|
|
# Database Connection for Development
|
|
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/stones"
|
|
|
|
# Authentication
|
|
AUTH_SECRET="dev-secret-key-for-testing"
|
|
|
|
# Application
|
|
NEXT_PUBLIC_APP_URL="http://localhost:3000"
|
|
EOF
|
|
echo -e "${YELLOW}Please update the .env.local file with your actual development database values.${NC}"
|
|
fi
|
|
|
|
# Install dependencies if node_modules doesn't exist
|
|
if [ ! -d "node_modules" ]; then
|
|
echo -e "${YELLOW}Installing dependencies...${NC}"
|
|
npm install
|
|
else
|
|
echo -e "${YELLOW}Dependencies already installed. To reinstall, remove the node_modules directory.${NC}"
|
|
fi
|
|
|
|
# Run database migrations if schema.prisma exists
|
|
if [ -f "prisma/schema.prisma" ]; then
|
|
echo -e "${YELLOW}Running database migrations...${NC}"
|
|
npx prisma migrate dev --name dev-migration
|
|
|
|
echo -e "${YELLOW}Generating Prisma client...${NC}"
|
|
npx prisma generate
|
|
fi
|
|
|
|
# Check PostgreSQL connectivity
|
|
echo -e "${YELLOW}Checking PostgreSQL connectivity...${NC}"
|
|
if command -v pg_isready &> /dev/null; then
|
|
if pg_isready -h localhost -p 5432; then
|
|
echo -e "${GREEN}PostgreSQL server is running at localhost:5432${NC}"
|
|
else
|
|
echo -e "${RED}Warning: PostgreSQL server at localhost:5432 is not responding${NC}"
|
|
echo -e "${RED}Please ensure your PostgreSQL server is running${NC}"
|
|
fi
|
|
else
|
|
echo -e "${YELLOW}pg_isready not found, skipping PostgreSQL connectivity check${NC}"
|
|
fi
|
|
|
|
# Add network debug information
|
|
echo -e "${YELLOW}Network interfaces:${NC}"
|
|
ip addr | grep "inet " | awk '{print $2}' | cut -d/ -f1
|
|
echo ""
|
|
|
|
# Create next.config.js file with proper configuration
|
|
echo -e "${YELLOW}Creating/updating next.config.js file...${NC}"
|
|
if [ -f "next.config.js" ]; then
|
|
mv next.config.js next.config.js.bak
|
|
fi
|
|
|
|
cat > next.config.js << EOF
|
|
/** @type {import('next').NextConfig} */
|
|
const nextConfig = {
|
|
reactStrictMode: true,
|
|
swcMinify: true,
|
|
}
|
|
|
|
module.exports = nextConfig
|
|
EOF
|
|
|
|
# Add HOST environment variable for Next.js to bind to all interfaces
|
|
echo -e "${YELLOW}Starting Next.js with HOST=0.0.0.0 to enable network access${NC}"
|
|
echo -e "${GREEN}Starting development server...${NC}"
|
|
echo -e "${GREEN}The application will be available at:${NC}"
|
|
echo -e "${GREEN} - http://localhost:3000${NC}"
|
|
ip addr | grep "inet " | grep -v "127.0.0.1" | awk '{print " - http://" $2 ":3000"}' | cut -d/ -f1
|
|
|
|
# Use HOST environment variable to allow access from any IP
|
|
HOST=0.0.0.0 npm run dev
|
|
|
|
# This part will execute when the server is stopped
|
|
echo -e "${YELLOW}Development server stopped.${NC}" |