diff --git a/.copier/config.yaml b/.copier/config.yaml index d9f108f..c39f5bb 100644 --- a/.copier/config.yaml +++ b/.copier/config.yaml @@ -43,6 +43,7 @@ workflows: - move: { from: "mflix/client", to: "client" } - move: { from: "mflix/server/java-spring", to: "server" } - copy: { from: "mflix/README-JAVA-SPRING.md", to: "README.md" } + - copy: { from: "mflix/check-requirements-java.sh", to: "check-requirements.sh" } - copy: { from: "mflix/.gitignore-java", to: ".gitignore" } commit_strategy: pr_title: "Update MFlix application from docs-sample-apps" @@ -68,6 +69,7 @@ workflows: - move: { from: "mflix/client", to: "client" } - move: { from: "mflix/server/js-express", to: "server" } - copy: { from: "mflix/README-JAVASCRIPT-EXPRESS.md", to: "README.md" } + - copy: { from: "mflix/check-requirements-js.sh", to: "check-requirements.sh" } - copy: { from: "mflix/.gitignore-js", to: ".gitignore" } commit_strategy: pr_title: "Update MFlix application from docs-sample-apps" @@ -93,6 +95,7 @@ workflows: - move: { from: "mflix/client", to: "client" } - move: { from: "mflix/server/python-fastapi", to: "server" } - copy: { from: "mflix/README-PYTHON-FASTAPI.md", to: "README.md" } + - copy: { from: "mflix/check-requirements-python.sh", to: "check-requirements.sh" } - copy: { from: "mflix/.gitignore-python", to: ".gitignore" } commit_strategy: pr_title: "Update MFlix application from docs-sample-apps" diff --git a/mflix/README-JAVA-SPRING.md b/mflix/README-JAVA-SPRING.md index 245afc5..a888664 100644 --- a/mflix/README-JAVA-SPRING.md +++ b/mflix/README-JAVA-SPRING.md @@ -28,6 +28,16 @@ The `sample_mflix` dataset contains movies released up to **2016**. Searching fo - **Voyage AI API key** (For MongoDB Vector Search) - [Get a Voyage AI API key](https://www.voyageai.com/) +## Verify Requirements + +Before getting started, you can run the verification script to check if you have all the necessary requirements: + +```bash +./check-requirements.sh +``` + +This script checks for required tools (Java, Maven, Node.js), validates your environment configuration, and verifies dependencies. Run with `--help` for more options. + ## Getting Started ### 1. Configure the Backend @@ -48,28 +58,19 @@ Edit the `.env` file and set your MongoDB connection string: ```env # MongoDB Connection -# Replace with your MongoDB Atlas connection string or local MongoDB URI MONGODB_URI=mongodb+srv://:@.mongodb.net/sample_mflix?retryWrites=true&w=majority -# Voyage AI Configuration -# API key for Voyage AI embedding model (required for Vector Search) +# Voyage AI Configuration (optional - required for Vector Search) VOYAGE_API_KEY=your_voyage_api_key # Server Configuration -# Port on which the Spring Boot application will run PORT=3001 # CORS Configuration -# Allowed origin for cross-origin requests (frontend URL) -# For multiple origins, separate with commas -CORS_ORIGIN=http://localhost:3000 - -# Optional: Enable MongoDB Search tests -# Uncomment the following line to enable Search tests -# ENABLE_SEARCH_TESTS=true +CORS_ORIGINS=http://localhost:3000 ``` -**Note:** Replace `username`, `password`, and `cluster` with your +**Note:** Replace ``, ``, and `` with your actual MongoDB Atlas credentials. Replace `your_voyage_api_key` with your key. diff --git a/mflix/README-JAVASCRIPT-EXPRESS.md b/mflix/README-JAVASCRIPT-EXPRESS.md index f3c531c..a7b8e75 100644 --- a/mflix/README-JAVASCRIPT-EXPRESS.md +++ b/mflix/README-JAVASCRIPT-EXPRESS.md @@ -27,6 +27,16 @@ The `sample_mflix` dataset contains movies released up to **2016**. Searching fo - **Voyage AI API key** (For MongoDB Vector Search) - [Get a Voyage AI API key](https://www.voyageai.com/) +## Verify Requirements + +Before getting started, you can run the verification script to check if you have all the necessary requirements: + +```bash +./check-requirements.sh +``` + +This script checks for required tools (Node.js, npm), validates your environment configuration, and verifies dependencies. Run with `--help` for more options. + ## Getting Started ### 1. Configure the Backend @@ -61,7 +71,7 @@ NODE_ENV=development # CORS Configuration # Allowed origin for cross-origin requests (frontend URL) # For multiple origins, separate with commas -CORS_ORIGIN=http://localhost:3000 +CORS_ORIGINS=http://localhost:3000 # Optional: Enable MongoDB Search tests # Uncomment the following line to enable Search tests diff --git a/mflix/README-PYTHON-FASTAPI.md b/mflix/README-PYTHON-FASTAPI.md index 3d79f3b..fdcf10d 100644 --- a/mflix/README-PYTHON-FASTAPI.md +++ b/mflix/README-PYTHON-FASTAPI.md @@ -31,6 +31,16 @@ The `sample_mflix` dataset contains movies released up to **2016**. Searching fo - **Voyage AI API key** (For MongoDB Vector Search) - [Get a Voyage AI API key](https://www.voyageai.com/) +## Verify Requirements + +Before getting started, you can run the verification script to check if you have all the necessary requirements: + +```bash +./check-requirements.sh +``` + +This script checks for required tools (Python, pip, Node.js), validates your environment configuration, and verifies dependencies. Run with `--help` for more options. + ## Getting Started ### 1. Configure the Backend @@ -50,21 +60,21 @@ cp .env.example .env Edit the `.env` file and set your MongoDB connection string: ```env -# MongoDB Configuration -MONGO_URI=mongodb+srv://:@.mongodb.net/sample_mflix?retryWrites=true&w=majority -MONGO_DB=sample_mflix +# MongoDB Connection +MONGODB_URI=mongodb+srv://:@.mongodb.net/sample_mflix?retryWrites=true&w=majority -# Voyage AI Configuration -# API key for Voyage AI embedding model (required for Vector Search) +# Voyage AI Configuration (optional - required for Vector Search) VOYAGE_API_KEY=your_voyage_api_key +# Server Configuration +PORT=3001 + # CORS Configuration -# Comma-separated list of allowed origins for CORS -CORS_ORIGINS=http://localhost:3000,http://localhost:3001 +CORS_ORIGINS=http://localhost:3000 ``` -**Note:** Replace `username`, `password`, and `cluster` with your actual MongoDB Atlas -credentials. +**Note:** Replace ``, ``, and `` with your actual MongoDB Atlas +credentials. Replace `your_voyage_api_key` with your key. Make a virtual environment: diff --git a/mflix/check-requirements-java.sh b/mflix/check-requirements-java.sh new file mode 100755 index 0000000..97dedb7 --- /dev/null +++ b/mflix/check-requirements-java.sh @@ -0,0 +1,436 @@ +#!/bin/bash +# ============================================================================= +# Requirements Verification Script for mflix Sample Application +# Java/Spring Boot Backend +# ============================================================================= +# +# This script checks that all necessary requirements are installed to run +# the mflix sample application with the Java/Spring Boot backend. +# +# Usage: +# ./check-requirements-java.sh # Check all requirements +# ./check-requirements-java.sh --setup # Check and auto-setup missing items +# ./check-requirements-java.sh --help # Show help message +# +# ============================================================================= + +# Exit on error (but handle arithmetic expressions carefully) +set -e + +# ============================================================================= +# Configuration +# ============================================================================= + +SERVER_DIR="server" +CLIENT_DIR="client" +JAVA_MIN_VERSION="21" +NODE_MIN_VERSION="18" + +# ============================================================================= +# Colors +# ============================================================================= + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# ============================================================================= +# Counters +# ============================================================================= + +CHECKS_PASSED=0 +CHECKS_FAILED=0 +CHECKS_WARNED=0 + +# ============================================================================= +# Helper Functions +# ============================================================================= + +print_header() { + echo "" + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" + echo -e "${BLUE} $1${NC}" + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" +} + +print_section() { + echo "" + echo -e "${YELLOW}▸ $1${NC}" +} + +check_pass() { + echo -e " ${GREEN}✓${NC} $1" + CHECKS_PASSED=$((CHECKS_PASSED + 1)) +} + +check_fail() { + echo -e " ${RED}✗${NC} $1" + CHECKS_FAILED=$((CHECKS_FAILED + 1)) +} + +check_warn() { + echo -e " ${YELLOW}⚠${NC} $1" + CHECKS_WARNED=$((CHECKS_WARNED + 1)) +} + +check_info() { + echo -e " ${BLUE}→${NC} $1" +} + +command_exists() { + command -v "$1" &>/dev/null +} + +version_gte() { + # Returns 0 (true) if $1 >= $2 (numeric comparison) + [[ "$1" -ge "$2" ]] 2>/dev/null +} + +show_help() { + echo "Usage: $0 [OPTIONS]" + echo "" + echo "Options:" + echo " --setup Attempt to automatically set up missing requirements" + echo " --help Show this help message" + echo "" + echo "This script checks that all necessary requirements are installed" + echo "to run the mflix sample application with the Java/Spring Boot backend." + exit 0 +} + + + +# ============================================================================= +# Check Java/Spring Boot Backend Requirements +# ============================================================================= + +check_backend_requirements() { + print_section "Java/Spring Boot Backend Requirements" + + local server_dir="$SCRIPT_DIR/$SERVER_DIR" + + # Check Java version + if command_exists java; then + local java_version + java_version=$(java -version 2>&1 | head -n1 | sed -E 's/.*version "([0-9]+).*/\1/') + if [[ -n "$java_version" ]] && version_gte "$java_version" "$JAVA_MIN_VERSION"; then + check_pass "Java $java_version installed (>= $JAVA_MIN_VERSION required)" + else + check_fail "Java $java_version installed but >= $JAVA_MIN_VERSION required" + check_info "Install Java $JAVA_MIN_VERSION+ from https://adoptium.net/" + fi + else + check_fail "Java not installed" + check_info "Install Java $JAVA_MIN_VERSION+ from https://adoptium.net/" + return + fi + + # Check JAVA_HOME + if [[ -n "$JAVA_HOME" ]]; then + if [[ -d "$JAVA_HOME" ]]; then + check_pass "JAVA_HOME is set: $JAVA_HOME" + else + check_warn "JAVA_HOME is set but directory doesn't exist: $JAVA_HOME" + fi + else + check_warn "JAVA_HOME is not set (may cause issues with some tools)" + check_info "Set JAVA_HOME to your Java installation directory" + fi + + # Check Maven wrapper + if [[ -f "$server_dir/mvnw" ]]; then + check_pass "Maven wrapper (mvnw) found" + + # Check if mvnw is executable + if [[ -x "$server_dir/mvnw" ]]; then + check_pass "Maven wrapper is executable" + else + check_warn "Maven wrapper is not executable" + if [[ "$SETUP_MODE" == true ]]; then + chmod +x "$server_dir/mvnw" + check_pass "Made Maven wrapper executable" + else + check_info "Run: chmod +x $SERVER_DIR/mvnw" + fi + fi + + # Try to get Maven version + local maven_version + maven_version=$(cd "$server_dir" && ./mvnw --version 2>/dev/null | grep "Apache Maven" | awk '{print $3}') + if [[ -n "$maven_version" ]]; then + check_pass "Maven version: $maven_version" + fi + else + check_fail "Maven wrapper (mvnw) not found in $SERVER_DIR" + check_info "The Maven wrapper should be included in the repository" + fi + + # Check if Maven dependencies are downloaded + if [[ -d "$server_dir/target" ]]; then + check_pass "Maven target directory exists (dependencies likely downloaded)" + else + check_warn "Maven target directory not found" + if [[ "$SETUP_MODE" == true ]]; then + check_info "Downloading Maven dependencies..." + if (cd "$server_dir" && ./mvnw dependency:resolve -q); then + check_pass "Maven dependencies downloaded successfully" + else + check_fail "Failed to download Maven dependencies" + fi + else + check_info "Run: cd $SERVER_DIR && ./mvnw dependency:resolve" + fi + fi + + # Check if project compiles + if [[ -d "$server_dir/target/classes" ]]; then + check_pass "Project appears to be compiled" + else + check_warn "Project not compiled yet" + if [[ "$SETUP_MODE" == true ]]; then + check_info "Compiling project..." + if (cd "$server_dir" && ./mvnw compile -q); then + check_pass "Project compiled successfully" + else + check_fail "Failed to compile project" + fi + else + check_info "Run: cd $SERVER_DIR && ./mvnw compile" + fi + fi +} + +# ============================================================================= +# Check Environment Configuration +# ============================================================================= + +check_env_configuration() { + print_section "Environment Configuration" + + local server_dir="$SCRIPT_DIR/$SERVER_DIR" + local env_file="$server_dir/.env" + local env_example="$server_dir/.env.example" + + # Check .env file + if [[ -f "$env_file" ]]; then + check_pass ".env file exists" + + # Check MONGODB_URI + if grep -q "^MONGODB_URI=" "$env_file" 2>/dev/null; then + local mongo_uri + mongo_uri=$(grep "^MONGODB_URI=" "$env_file" | cut -d'=' -f2-) + if [[ -n "$mongo_uri" ]] && [[ "$mongo_uri" != *"<"*">"* ]]; then + check_pass "MONGODB_URI is configured" + else + check_fail "MONGODB_URI is not configured (still has placeholder value)" + check_info "Update MONGODB_URI in $SERVER_DIR/.env with your MongoDB connection string" + fi + else + check_fail "MONGODB_URI not found in .env" + check_info "Add MONGODB_URI to $SERVER_DIR/.env" + fi + + # Check VOYAGE_API_KEY (optional) + if grep -q "^VOYAGE_API_KEY=" "$env_file" 2>/dev/null; then + local voyage_key + voyage_key=$(grep "^VOYAGE_API_KEY=" "$env_file" | cut -d'=' -f2-) + if [[ -n "$voyage_key" ]] && [[ "$voyage_key" != "your_voyage_api_key" ]]; then + check_pass "VOYAGE_API_KEY is configured" + else + check_info "VOYAGE_API_KEY not configured (optional - needed for vector search)" + fi + else + check_info "VOYAGE_API_KEY not set (optional - needed for vector search)" + fi + + # Check CORS_ORIGINS (optional) + if grep -q "^CORS_ORIGINS=" "$env_file" 2>/dev/null; then + check_pass "CORS_ORIGINS is configured" + else + check_info "CORS_ORIGINS not set (will use default: http://localhost:3000)" + fi + + # Check PORT (optional) + if grep -q "^PORT=" "$env_file" 2>/dev/null; then + check_pass "PORT is configured" + else + check_info "PORT not set (will use default: 3001)" + fi + else + check_warn ".env file not found" + if [[ -f "$env_example" ]]; then + if [[ "$SETUP_MODE" == true ]]; then + check_info "Creating .env from .env.example..." + if cp "$env_example" "$env_file"; then + check_pass ".env file created from .env.example" + check_warn "Please update the placeholder values in $SERVER_DIR/.env" + else + check_fail "Failed to create .env file" + fi + else + check_info "Copy .env.example to .env: cp $SERVER_DIR/.env.example $SERVER_DIR/.env" + fi + else + check_fail "No .env.example found to use as template" + fi + fi +} + +# ============================================================================= +# Check Frontend Requirements +# ============================================================================= + +check_frontend_requirements() { + print_section "Frontend Requirements (Next.js)" + + local client_dir="$SCRIPT_DIR/$CLIENT_DIR" + + # Check Node.js + if command_exists node; then + local node_version + node_version=$(node --version | sed 's/v//') + local node_major + node_major=$(echo "$node_version" | cut -d. -f1) + if [[ "$node_major" -ge "$NODE_MIN_VERSION" ]]; then + check_pass "Node.js installed (version $node_version, >= $NODE_MIN_VERSION required)" + else + check_fail "Node.js version $node_version is below minimum required ($NODE_MIN_VERSION+)" + check_info "Install Node.js $NODE_MIN_VERSION+: https://nodejs.org/" + fi + else + check_fail "Node.js not installed" + check_info "Install Node.js $NODE_MIN_VERSION+: https://nodejs.org/" + return + fi + + # Check npm + if command_exists npm; then + local npm_version + npm_version=$(npm --version) + check_pass "npm installed (version $npm_version)" + else + check_fail "npm not installed" + check_info "npm should come with Node.js installation" + return + fi + + # Check client directory + if [[ ! -d "$client_dir" ]]; then + check_warn "Client directory not found: $CLIENT_DIR" + check_info "Frontend may be in a separate repository" + return + fi + + # Check client dependencies + if [[ -d "$client_dir/node_modules" ]]; then + check_pass "Frontend dependencies installed" + + # Check Next.js + if [[ -d "$client_dir/node_modules/next" ]]; then + check_pass "Next.js dependency installed" + else + check_warn "Next.js not found in dependencies" + fi + + # Check React + if [[ -d "$client_dir/node_modules/react" ]]; then + check_pass "React dependency installed" + else + check_warn "React not found in dependencies" + fi + else + check_warn "Frontend dependencies not installed" + if [[ "$SETUP_MODE" == true ]]; then + check_info "Installing frontend dependencies..." + if (cd "$client_dir" && npm install &>/dev/null); then + check_pass "Frontend dependencies installed successfully" + else + check_fail "Failed to install frontend dependencies" + fi + else + check_info "Run: cd $CLIENT_DIR && npm install" + fi + fi +} + +# ============================================================================= +# Print Summary +# ============================================================================= + +print_summary() { + print_header "Summary" + echo "" + echo -e " ${GREEN}Passed:${NC} $CHECKS_PASSED" + echo -e " ${RED}Failed:${NC} $CHECKS_FAILED" + echo -e " ${YELLOW}Warnings:${NC} $CHECKS_WARNED" + echo "" + + if [[ $CHECKS_FAILED -eq 0 ]]; then + echo -e "${GREEN}All required checks passed!${NC}" + if [[ $CHECKS_WARNED -gt 0 ]]; then + echo -e "${YELLOW}There are some warnings to review.${NC}" + fi + else + echo -e "${RED}Some checks failed. Please address the issues above.${NC}" + if [[ "$SETUP_MODE" != true ]]; then + echo -e "${BLUE}Tip: Run with --setup flag to auto-fix some issues${NC}" + fi + fi + echo "" +} + +# ============================================================================= +# Main Execution +# ============================================================================= + +# Get script directory and change to it +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$SCRIPT_DIR" + +# Default options +SETUP_MODE=false + +# Parse arguments +while [[ $# -gt 0 ]]; do + case $1 in + --setup) + SETUP_MODE=true + shift + ;; + --help|-h) + show_help + ;; + *) + echo "Unknown option: $1" + echo "Use --help for usage information" + exit 1 + ;; + esac +done + +# Print banner +echo "" +echo -e "${BLUE}╔══════════════════════════════════════════════════════════════╗${NC}" +echo -e "${BLUE}║ mflix Sample Application - Requirements Check ║${NC}" +echo -e "${BLUE}║ Java/Spring Boot Backend ║${NC}" +echo -e "${BLUE}╚══════════════════════════════════════════════════════════════╝${NC}" + +if [[ "$SETUP_MODE" == true ]]; then + echo -e "${YELLOW}Running in setup mode - will attempt to fix issues${NC}" +fi + +# Run all checks +check_backend_requirements +check_env_configuration +check_frontend_requirements + +# Print summary +print_summary + +# Exit with appropriate code +if [[ $CHECKS_FAILED -gt 0 ]]; then + exit 1 +fi +exit 0 \ No newline at end of file diff --git a/mflix/check-requirements-js.sh b/mflix/check-requirements-js.sh new file mode 100755 index 0000000..a588fe0 --- /dev/null +++ b/mflix/check-requirements-js.sh @@ -0,0 +1,427 @@ +#!/bin/bash +# ============================================================================= +# Requirements Verification Script for mflix Sample Application +# JavaScript/Express Backend +# ============================================================================= +# +# This script checks that all necessary requirements are installed to run +# the mflix sample application with the JavaScript/Express backend. +# +# Usage: +# ./check-requirements-js.sh # Check all requirements +# ./check-requirements-js.sh --setup # Check and auto-setup missing items +# ./check-requirements-js.sh --help # Show help message +# +# ============================================================================= + +# Exit on error (but handle arithmetic expressions carefully) +set -e + +# ============================================================================= +# Configuration +# ============================================================================= + +SERVER_DIR="server" +CLIENT_DIR="client" +NODE_MIN_VERSION="18" + +# ============================================================================= +# Colors +# ============================================================================= + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# ============================================================================= +# Counters +# ============================================================================= + +CHECKS_PASSED=0 +CHECKS_FAILED=0 +CHECKS_WARNED=0 + +# ============================================================================= +# Helper Functions +# ============================================================================= + +print_header() { + echo "" + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" + echo -e "${BLUE} $1${NC}" + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" +} + +print_section() { + echo "" + echo -e "${YELLOW}▸ $1${NC}" +} + +check_pass() { + echo -e " ${GREEN}✓${NC} $1" + CHECKS_PASSED=$((CHECKS_PASSED + 1)) +} + +check_fail() { + echo -e " ${RED}✗${NC} $1" + CHECKS_FAILED=$((CHECKS_FAILED + 1)) +} + +check_warn() { + echo -e " ${YELLOW}⚠${NC} $1" + CHECKS_WARNED=$((CHECKS_WARNED + 1)) +} + +check_info() { + echo -e " ${BLUE}→${NC} $1" +} + +command_exists() { + command -v "$1" &>/dev/null +} + +version_gte() { + # Returns 0 (true) if $1 >= $2 (numeric comparison) + [[ "$1" -ge "$2" ]] 2>/dev/null +} + +show_help() { + echo "Usage: $0 [OPTIONS]" + echo "" + echo "Options:" + echo " --setup Attempt to automatically set up missing requirements" + echo " --help Show this help message" + echo "" + echo "This script checks that all necessary requirements are installed" + echo "to run the mflix sample application with the JavaScript/Express backend." + exit 0 +} + + + +# ============================================================================= +# Check JavaScript/Express Backend Requirements +# ============================================================================= + +check_backend_requirements() { + print_section "JavaScript/Express Backend Requirements" + + local server_dir="$SCRIPT_DIR/$SERVER_DIR" + + # Check Node.js version + if command_exists node; then + local node_version + node_version=$(node --version | sed 's/v//') + local node_major + node_major=$(echo "$node_version" | cut -d. -f1) + if [[ "$node_major" -ge "$NODE_MIN_VERSION" ]]; then + check_pass "Node.js $node_version installed (>= $NODE_MIN_VERSION required)" + else + check_fail "Node.js $node_version installed but >= $NODE_MIN_VERSION required" + check_info "Install Node.js $NODE_MIN_VERSION+ from https://nodejs.org/" + fi + else + check_fail "Node.js not installed" + check_info "Install Node.js $NODE_MIN_VERSION+ from https://nodejs.org/" + return + fi + + # Check npm + if command_exists npm; then + local npm_version + npm_version=$(npm --version) + check_pass "npm installed (version $npm_version)" + else + check_fail "npm not installed" + check_info "npm should come with Node.js installation" + return + fi + + # Check server directory + if [[ ! -d "$server_dir" ]]; then + check_fail "Server directory not found: $SERVER_DIR" + return + fi + + # Check package.json + if [[ -f "$server_dir/package.json" ]]; then + check_pass "package.json found" + else + check_fail "package.json not found in $SERVER_DIR" + return + fi + + # Check node_modules + if [[ -d "$server_dir/node_modules" ]]; then + check_pass "node_modules directory exists" + + # Check Express.js + if [[ -d "$server_dir/node_modules/express" ]]; then + check_pass "Express.js dependency installed" + else + check_fail "Express.js dependency not installed" + fi + + # Check MongoDB driver + if [[ -d "$server_dir/node_modules/mongodb" ]]; then + check_pass "MongoDB driver dependency installed" + else + check_fail "MongoDB driver dependency not installed" + fi + + # Check TypeScript build + if [[ -d "$server_dir/dist" ]]; then + check_pass "TypeScript build output exists (dist directory)" + else + check_warn "TypeScript build output not found (dist directory)" + check_info "Run: cd $SERVER_DIR && npm run build" + fi + else + check_warn "node_modules directory not found" + if [[ "$SETUP_MODE" == true ]]; then + check_info "Installing dependencies..." + if (cd "$server_dir" && npm install &>/dev/null); then + check_pass "Dependencies installed successfully" + else + check_fail "Failed to install dependencies" + fi + else + check_info "Run: cd $SERVER_DIR && npm install" + fi + fi +} + +# ============================================================================= +# Check Environment Configuration +# ============================================================================= + +check_env_configuration() { + print_section "Environment Configuration" + + local server_dir="$SCRIPT_DIR/$SERVER_DIR" + local env_file="$server_dir/.env" + local env_example="$server_dir/.env.example" + + # Check .env file + if [[ -f "$env_file" ]]; then + check_pass ".env file exists" + + # Check MONGODB_URI + if grep -q "^MONGODB_URI=" "$env_file" 2>/dev/null; then + local mongo_uri + mongo_uri=$(grep "^MONGODB_URI=" "$env_file" | cut -d'=' -f2-) + if [[ -n "$mongo_uri" ]] && [[ "$mongo_uri" != *"<"*">"* ]]; then + check_pass "MONGODB_URI is configured" + else + check_fail "MONGODB_URI is not configured (still has placeholder value)" + check_info "Update MONGODB_URI in $SERVER_DIR/.env with your MongoDB connection string" + fi + else + check_fail "MONGODB_URI not found in .env" + check_info "Add MONGODB_URI to $SERVER_DIR/.env" + fi + + # Check VOYAGE_API_KEY (optional) + if grep -q "^VOYAGE_API_KEY=" "$env_file" 2>/dev/null; then + local voyage_key + voyage_key=$(grep "^VOYAGE_API_KEY=" "$env_file" | cut -d'=' -f2-) + if [[ -n "$voyage_key" ]] && [[ "$voyage_key" != "your_voyage_api_key" ]]; then + check_pass "VOYAGE_API_KEY is configured" + else + check_info "VOYAGE_API_KEY not configured (optional - needed for vector search)" + fi + else + check_info "VOYAGE_API_KEY not set (optional - needed for vector search)" + fi + + # Check CORS_ORIGINS (optional) + if grep -q "^CORS_ORIGINS=" "$env_file" 2>/dev/null; then + check_pass "CORS_ORIGINS is configured" + else + check_info "CORS_ORIGINS not set (will use default: http://localhost:3000)" + fi + + # Check PORT (optional) + if grep -q "^PORT=" "$env_file" 2>/dev/null; then + check_pass "PORT is configured" + else + check_info "PORT not set (will use default: 3001)" + fi + else + check_warn ".env file not found" + if [[ -f "$env_example" ]]; then + if [[ "$SETUP_MODE" == true ]]; then + check_info "Creating .env from .env.example..." + if cp "$env_example" "$env_file"; then + check_pass ".env file created from .env.example" + check_warn "Please update the placeholder values in $SERVER_DIR/.env" + else + check_fail "Failed to create .env file" + fi + else + check_info "Copy .env.example to .env: cp $SERVER_DIR/.env.example $SERVER_DIR/.env" + fi + else + check_fail "No .env.example found to use as template" + fi + fi +} + +# ============================================================================= +# Check Frontend Requirements +# ============================================================================= + +check_frontend_requirements() { + print_section "Frontend Requirements (Next.js)" + + local client_dir="$SCRIPT_DIR/$CLIENT_DIR" + + # Check Node.js + if command_exists node; then + local node_version + node_version=$(node --version | sed 's/v//') + local node_major + node_major=$(echo "$node_version" | cut -d. -f1) + if [[ "$node_major" -ge "$NODE_MIN_VERSION" ]]; then + check_pass "Node.js installed (version $node_version, >= $NODE_MIN_VERSION required)" + else + check_fail "Node.js version $node_version is below minimum required ($NODE_MIN_VERSION+)" + check_info "Install Node.js $NODE_MIN_VERSION+: https://nodejs.org/" + fi + else + check_fail "Node.js not installed" + check_info "Install Node.js $NODE_MIN_VERSION+: https://nodejs.org/" + return + fi + + # Check npm + if command_exists npm; then + local npm_version + npm_version=$(npm --version) + check_pass "npm installed (version $npm_version)" + else + check_fail "npm not installed" + check_info "npm should come with Node.js installation" + return + fi + + # Check client directory + if [[ ! -d "$client_dir" ]]; then + check_warn "Client directory not found: $CLIENT_DIR" + check_info "Frontend may be in a separate repository" + return + fi + + # Check client dependencies + if [[ -d "$client_dir/node_modules" ]]; then + check_pass "Frontend dependencies installed" + + # Check Next.js + if [[ -d "$client_dir/node_modules/next" ]]; then + check_pass "Next.js dependency installed" + else + check_warn "Next.js not found in dependencies" + fi + + # Check React + if [[ -d "$client_dir/node_modules/react" ]]; then + check_pass "React dependency installed" + else + check_warn "React not found in dependencies" + fi + else + check_warn "Frontend dependencies not installed" + if [[ "$SETUP_MODE" == true ]]; then + check_info "Installing frontend dependencies..." + if (cd "$client_dir" && npm install &>/dev/null); then + check_pass "Frontend dependencies installed successfully" + else + check_fail "Failed to install frontend dependencies" + fi + else + check_info "Run: cd $CLIENT_DIR && npm install" + fi + fi +} + +# ============================================================================= +# Print Summary +# ============================================================================= + +print_summary() { + print_header "Summary" + echo "" + echo -e " ${GREEN}Passed:${NC} $CHECKS_PASSED" + echo -e " ${RED}Failed:${NC} $CHECKS_FAILED" + echo -e " ${YELLOW}Warnings:${NC} $CHECKS_WARNED" + echo "" + + if [[ $CHECKS_FAILED -eq 0 ]]; then + echo -e "${GREEN}All required checks passed!${NC}" + if [[ $CHECKS_WARNED -gt 0 ]]; then + echo -e "${YELLOW}There are some warnings to review.${NC}" + fi + else + echo -e "${RED}Some checks failed. Please address the issues above.${NC}" + if [[ "$SETUP_MODE" != true ]]; then + echo -e "${BLUE}Tip: Run with --setup flag to auto-fix some issues${NC}" + fi + fi + echo "" +} + +# ============================================================================= +# Main Execution +# ============================================================================= + +# Get script directory and change to it +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$SCRIPT_DIR" + +# Default options +SETUP_MODE=false + +# Parse arguments +while [[ $# -gt 0 ]]; do + case $1 in + --setup) + SETUP_MODE=true + shift + ;; + --help|-h) + show_help + ;; + *) + echo "Unknown option: $1" + echo "Use --help for usage information" + exit 1 + ;; + esac +done + +# Print banner +echo "" +echo -e "${BLUE}╔══════════════════════════════════════════════════════════════╗${NC}" +echo -e "${BLUE}║ mflix Sample Application - Requirements Check ║${NC}" +echo -e "${BLUE}║ JavaScript/Express Backend ║${NC}" +echo -e "${BLUE}╚══════════════════════════════════════════════════════════════╝${NC}" + +if [[ "$SETUP_MODE" == true ]]; then + echo -e "${YELLOW}Running in setup mode - will attempt to fix issues${NC}" +fi + +# Run all checks +check_backend_requirements +check_env_configuration +check_frontend_requirements + +# Print summary +print_summary + +# Exit with appropriate code +if [[ $CHECKS_FAILED -gt 0 ]]; then + exit 1 +fi +exit 0 diff --git a/mflix/check-requirements-python.sh b/mflix/check-requirements-python.sh new file mode 100755 index 0000000..ea1249c --- /dev/null +++ b/mflix/check-requirements-python.sh @@ -0,0 +1,433 @@ +#!/bin/bash +# ============================================================================= +# Requirements Verification Script for mflix Sample Application +# Python/FastAPI Backend +# ============================================================================= +# +# This script checks that all necessary requirements are installed to run +# the mflix sample application with the Python/FastAPI backend. +# +# Usage: +# ./check-requirements-python.sh # Check all requirements +# ./check-requirements-python.sh --setup # Check and auto-setup missing items +# ./check-requirements-python.sh --help # Show help message +# +# ============================================================================= + +# Exit on error (but handle arithmetic expressions carefully) +set -e + +# ============================================================================= +# Configuration +# ============================================================================= + +SERVER_DIR="server" +CLIENT_DIR="client" +PYTHON_MIN_VERSION="3.11" +NODE_MIN_VERSION="18" + +# ============================================================================= +# Colors +# ============================================================================= + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# ============================================================================= +# Counters +# ============================================================================= + +CHECKS_PASSED=0 +CHECKS_FAILED=0 +CHECKS_WARNED=0 + +# ============================================================================= +# Helper Functions +# ============================================================================= + +print_header() { + echo "" + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" + echo -e "${BLUE} $1${NC}" + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" +} + +print_section() { + echo "" + echo -e "${YELLOW}▸ $1${NC}" +} + +check_pass() { + echo -e " ${GREEN}✓${NC} $1" + CHECKS_PASSED=$((CHECKS_PASSED + 1)) +} + +check_fail() { + echo -e " ${RED}✗${NC} $1" + CHECKS_FAILED=$((CHECKS_FAILED + 1)) +} + +check_warn() { + echo -e " ${YELLOW}⚠${NC} $1" + CHECKS_WARNED=$((CHECKS_WARNED + 1)) +} + +check_info() { + echo -e " ${BLUE}→${NC} $1" +} + +command_exists() { + command -v "$1" &>/dev/null +} + +version_gte() { + # Returns 0 (true) if $1 >= $2 using version sorting + [ "$(printf '%s\n' "$2" "$1" | sort -V | head -n1)" = "$2" ] +} + +show_help() { + echo "Usage: $0 [OPTIONS]" + echo "" + echo "Options:" + echo " --setup Attempt to automatically set up missing requirements" + echo " --help Show this help message" + echo "" + echo "This script checks that all necessary requirements are installed" + echo "to run the mflix sample application with the Python/FastAPI backend." + exit 0 +} + + + +# ============================================================================= +# Check Python/FastAPI Backend Requirements +# ============================================================================= + +check_backend_requirements() { + print_section "Python/FastAPI Backend Requirements" + + local server_dir="$SCRIPT_DIR/$SERVER_DIR" + + # Check Python version + if command_exists python3; then + local python_version + python_version=$(python3 --version 2>&1 | grep -oE '[0-9]+\.[0-9]+' | head -1) + if version_gte "$python_version" "$PYTHON_MIN_VERSION"; then + check_pass "Python $python_version installed (>= $PYTHON_MIN_VERSION required)" + else + check_fail "Python $python_version installed but >= $PYTHON_MIN_VERSION required" + check_info "Install Python $PYTHON_MIN_VERSION+ from https://www.python.org/downloads/" + fi + else + check_fail "Python 3 not installed" + check_info "Install Python $PYTHON_MIN_VERSION+ from https://www.python.org/downloads/" + return + fi + + # Check pip + if command_exists pip3 || python3 -m pip --version &>/dev/null; then + check_pass "pip installed" + else + check_fail "pip not installed" + check_info "Install pip: python3 -m ensurepip --upgrade" + fi + + # Check virtual environment + local venv_dir="$server_dir/.venv" + if [[ -d "$venv_dir" ]]; then + check_pass "Python virtual environment exists at $SERVER_DIR/.venv" + + # Check if venv activation script exists + if [[ -f "$venv_dir/bin/activate" ]]; then + check_pass "Virtual environment activation script exists" + else + check_warn "Virtual environment activation script missing" + fi + else + check_warn "Python virtual environment not found at $SERVER_DIR/.venv" + if [[ "$SETUP_MODE" == true ]]; then + check_info "Creating virtual environment..." + if python3 -m venv "$venv_dir"; then + check_pass "Virtual environment created" + else + check_fail "Failed to create virtual environment" + fi + else + check_info "Create with: cd $SERVER_DIR && python3 -m venv .venv" + fi + fi + + # Check Python dependencies + local requirements_file="$server_dir/requirements.txt" + if [[ -f "$requirements_file" ]]; then + check_pass "requirements.txt found" + + # Check if key dependencies are installed + if [[ -d "$venv_dir" ]]; then + local pip_cmd="$venv_dir/bin/pip" + if [[ -f "$pip_cmd" ]]; then + # Check FastAPI + if "$pip_cmd" show fastapi &>/dev/null; then + check_pass "FastAPI installed in virtual environment" + else + check_warn "FastAPI not installed in virtual environment" + if [[ "$SETUP_MODE" == true ]]; then + check_info "Installing dependencies..." + if "$pip_cmd" install -r "$requirements_file" &>/dev/null; then + check_pass "Dependencies installed" + else + check_fail "Failed to install dependencies" + fi + else + check_info "Install with: source $SERVER_DIR/.venv/bin/activate && pip install -r $SERVER_DIR/requirements.txt" + fi + fi + + # Check PyMongo + if "$pip_cmd" show pymongo &>/dev/null; then + check_pass "PyMongo installed in virtual environment" + else + check_warn "PyMongo not installed in virtual environment" + fi + fi + fi + else + check_fail "requirements.txt not found at $SERVER_DIR/requirements.txt" + fi +} + +# ============================================================================= +# Check Environment Configuration +# ============================================================================= + +check_env_configuration() { + print_section "Environment Configuration" + + local server_dir="$SCRIPT_DIR/$SERVER_DIR" + local env_file="$server_dir/.env" + local env_example="$server_dir/.env.example" + + # Check .env file + if [[ -f "$env_file" ]]; then + check_pass ".env file exists" + + # Check MONGODB_URI + if grep -q "^MONGODB_URI=" "$env_file" 2>/dev/null; then + local mongo_uri + mongo_uri=$(grep "^MONGODB_URI=" "$env_file" | cut -d'=' -f2-) + if [[ -n "$mongo_uri" ]] && [[ "$mongo_uri" != *"<"*">"* ]]; then + check_pass "MONGODB_URI is configured" + else + check_fail "MONGODB_URI is not configured (still has placeholder value)" + check_info "Update MONGODB_URI in $SERVER_DIR/.env with your MongoDB connection string" + fi + else + check_fail "MONGODB_URI not found in .env" + check_info "Add MONGODB_URI to $SERVER_DIR/.env" + fi + + # Check VOYAGE_API_KEY (optional) + if grep -q "^VOYAGE_API_KEY=" "$env_file" 2>/dev/null; then + local voyage_key + voyage_key=$(grep "^VOYAGE_API_KEY=" "$env_file" | cut -d'=' -f2-) + if [[ -n "$voyage_key" ]] && [[ "$voyage_key" != "your_voyage_api_key" ]]; then + check_pass "VOYAGE_API_KEY is configured" + else + check_info "VOYAGE_API_KEY not configured (optional - needed for vector search)" + fi + else + check_info "VOYAGE_API_KEY not set (optional - needed for vector search)" + fi + + # Check CORS_ORIGINS (optional) + if grep -q "^CORS_ORIGINS=" "$env_file" 2>/dev/null; then + check_pass "CORS_ORIGINS is configured" + else + check_info "CORS_ORIGINS not set (will use default: http://localhost:3000)" + fi + + # Check PORT (optional) + if grep -q "^PORT=" "$env_file" 2>/dev/null; then + check_pass "PORT is configured" + else + check_info "PORT not set (will use default: 3001)" + fi + else + check_warn ".env file not found" + if [[ -f "$env_example" ]]; then + if [[ "$SETUP_MODE" == true ]]; then + check_info "Creating .env from .env.example..." + if cp "$env_example" "$env_file"; then + check_pass ".env file created from .env.example" + check_warn "Please update the placeholder values in $SERVER_DIR/.env" + else + check_fail "Failed to create .env file" + fi + else + check_info "Copy .env.example to .env: cp $SERVER_DIR/.env.example $SERVER_DIR/.env" + fi + else + check_fail "No .env.example found to use as template" + fi + fi +} + +# ============================================================================= +# Check Frontend Requirements +# ============================================================================= + +check_frontend_requirements() { + print_section "Frontend Requirements (Next.js)" + + local client_dir="$SCRIPT_DIR/$CLIENT_DIR" + + # Check Node.js + if command_exists node; then + local node_version + node_version=$(node --version | sed 's/v//') + local node_major + node_major=$(echo "$node_version" | cut -d. -f1) + if [[ "$node_major" -ge "$NODE_MIN_VERSION" ]]; then + check_pass "Node.js installed (version $node_version, >= $NODE_MIN_VERSION required)" + else + check_fail "Node.js version $node_version is below minimum required ($NODE_MIN_VERSION+)" + check_info "Install Node.js $NODE_MIN_VERSION+: https://nodejs.org/" + fi + else + check_fail "Node.js not installed" + check_info "Install Node.js $NODE_MIN_VERSION+: https://nodejs.org/" + return + fi + + # Check npm + if command_exists npm; then + local npm_version + npm_version=$(npm --version) + check_pass "npm installed (version $npm_version)" + else + check_fail "npm not installed" + check_info "npm should come with Node.js installation" + return + fi + + # Check client directory + if [[ ! -d "$client_dir" ]]; then + check_warn "Client directory not found: $CLIENT_DIR" + check_info "Frontend may be in a separate repository" + return + fi + + # Check client dependencies + if [[ -d "$client_dir/node_modules" ]]; then + check_pass "Frontend dependencies installed" + + # Check Next.js + if [[ -d "$client_dir/node_modules/next" ]]; then + check_pass "Next.js dependency installed" + else + check_warn "Next.js not found in dependencies" + fi + + # Check React + if [[ -d "$client_dir/node_modules/react" ]]; then + check_pass "React dependency installed" + else + check_warn "React not found in dependencies" + fi + else + check_warn "Frontend dependencies not installed" + if [[ "$SETUP_MODE" == true ]]; then + check_info "Installing frontend dependencies..." + if (cd "$client_dir" && npm install &>/dev/null); then + check_pass "Frontend dependencies installed successfully" + else + check_fail "Failed to install frontend dependencies" + fi + else + check_info "Run: cd $CLIENT_DIR && npm install" + fi + fi +} + +# ============================================================================= +# Print Summary +# ============================================================================= + +print_summary() { + print_header "Summary" + echo "" + echo -e " ${GREEN}Passed:${NC} $CHECKS_PASSED" + echo -e " ${RED}Failed:${NC} $CHECKS_FAILED" + echo -e " ${YELLOW}Warnings:${NC} $CHECKS_WARNED" + echo "" + + if [[ $CHECKS_FAILED -eq 0 ]]; then + echo -e "${GREEN}All required checks passed!${NC}" + if [[ $CHECKS_WARNED -gt 0 ]]; then + echo -e "${YELLOW}There are some warnings to review.${NC}" + fi + else + echo -e "${RED}Some checks failed. Please address the issues above.${NC}" + if [[ "$SETUP_MODE" != true ]]; then + echo -e "${BLUE}Tip: Run with --setup flag to auto-fix some issues${NC}" + fi + fi + echo "" +} + +# ============================================================================= +# Main Execution +# ============================================================================= + +# Get script directory and change to it +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$SCRIPT_DIR" + +# Default options +SETUP_MODE=false + +# Parse arguments +while [[ $# -gt 0 ]]; do + case $1 in + --setup) + SETUP_MODE=true + shift + ;; + --help|-h) + show_help + ;; + *) + echo "Unknown option: $1" + echo "Use --help for usage information" + exit 1 + ;; + esac +done + +# Print banner +echo "" +echo -e "${BLUE}╔══════════════════════════════════════════════════════════════╗${NC}" +echo -e "${BLUE}║ mflix Sample Application - Requirements Check ║${NC}" +echo -e "${BLUE}║ Python/FastAPI Backend ║${NC}" +echo -e "${BLUE}╚══════════════════════════════════════════════════════════════╝${NC}" + +if [[ "$SETUP_MODE" == true ]]; then + echo -e "${YELLOW}Running in setup mode - will attempt to fix issues${NC}" +fi + +# Run all checks +check_backend_requirements +check_env_configuration +check_frontend_requirements + +# Print summary +print_summary + +# Exit with appropriate code +if [[ $CHECKS_FAILED -gt 0 ]]; then + exit 1 +fi +exit 0 diff --git a/mflix/server/java-spring/.env.example b/mflix/server/java-spring/.env.example index 049e6e9..96c3555 100644 --- a/mflix/server/java-spring/.env.example +++ b/mflix/server/java-spring/.env.example @@ -2,21 +2,19 @@ # Replace with your MongoDB Atlas connection string or local MongoDB URI MONGODB_URI=mongodb+srv://:@.mongodb.net/sample_mflix?retryWrites=true&w=majority -# Optional: Voyage AI Configuration -# API key for Voyage AI embedding model (required for Vector Search) +# OPTIONAL: Voyage AI Configuration (required for Vector Search) # Get your API key from https://www.voyageai.com/ -# Uncomment the following line to enable vector search -# VOYAGE_API_KEY=your-api-key +# VOYAGE_API_KEY=your_voyage_api_key # Server Configuration -# Port on which the Spring Boot application will run PORT=3001 # CORS Configuration -# Allowed origin for cross-origin requests (frontend URL) -# For multiple origins, separate with commas -CORS_ORIGIN=http://localhost:3000 +# Comma-separated list of allowed origins for cross-origin requests +CORS_ORIGINS=http://localhost:3000 -# Optional: Enable MongoDB Search tests -# Uncomment the following line to enable Search tests -# ENABLE_SEARCH_TESTS=true \ No newline at end of file +# Logging Configuration +# Log level: TRACE, DEBUG, INFO, WARN, ERROR (default: INFO) +LOG_LEVEL=INFO +# Optional: Path to log file (if not set, logs only to console) +# LOG_FILE=app.log \ No newline at end of file diff --git a/mflix/server/java-spring/src/main/resources/application.properties b/mflix/server/java-spring/src/main/resources/application.properties index ffe611f..47bd6d0 100644 --- a/mflix/server/java-spring/src/main/resources/application.properties +++ b/mflix/server/java-spring/src/main/resources/application.properties @@ -8,8 +8,8 @@ spring.data.mongodb.database=sample_mflix server.port=${PORT:3001} # CORS Configuration -# Allowed origins for cross-origin requests (typically the frontend URL) -cors.allowed.origins=${CORS_ORIGIN:http://localhost:3000} +# Comma-separated list of allowed origins for cross-origin requests +cors.allowed.origins=${CORS_ORIGINS:http://localhost:3000} # Voyage AI Configuration # API key for Voyage AI embedding model (required for vector search) diff --git a/mflix/server/js-express/.env.example b/mflix/server/js-express/.env.example index c870ee0..8b264f6 100644 --- a/mflix/server/js-express/.env.example +++ b/mflix/server/js-express/.env.example @@ -2,24 +2,19 @@ # Replace with your MongoDB Atlas connection string or local MongoDB URI MONGODB_URI=mongodb+srv://:@.mongodb.net/sample_mflix?retryWrites=true&w=majority -# Voyage AI Configuration -# API key for Voyage AI embedding model (required for Vector Search) -VOYAGE_API_KEY=your_voyage_api_key +# OPTIONAL: Voyage AI Configuration (required for Vector Search) +# Get your API key from https://www.voyageai.com/ +# VOYAGE_API_KEY=your_voyage_api_key # Server Configuration PORT=3001 NODE_ENV=development +# CORS Configuration +# Comma-separated list of allowed origins for cross-origin requests +CORS_ORIGINS=http://localhost:3000 + # Logging Configuration # Available levels: error, warn, info, http, debug # Default: debug (development), info (production), error (test) -LOG_LEVEL=debug - -# CORS Configuration -# Allowed origin for cross-origin requests (frontend URL) -# For multiple origins, separate with commas -CORS_ORIGIN=http://localhost:3000 - -# Optional: Enable MongoDB Search tests -# Uncomment the following line to enable Search tests -# ENABLE_SEARCH_TESTS=true \ No newline at end of file +LOG_LEVEL=debug \ No newline at end of file diff --git a/mflix/server/js-express/src/app.ts b/mflix/server/js-express/src/app.ts index 6e3d389..d6f2e99 100644 --- a/mflix/server/js-express/src/app.ts +++ b/mflix/server/js-express/src/app.ts @@ -32,10 +32,15 @@ const PORT = process.env.PORT || 3001; * CORS Configuration * Allows the frontend to communicate with this Express backend * In production, this should be configured to only allow specific origins + * Supports multiple origins via comma-separated CORS_ORIGINS environment variable */ +const corsOrigins = (process.env.CORS_ORIGINS || "http://localhost:3000") + .split(",") + .map((origin) => origin.trim()); + app.use( cors({ - origin: process.env.CORS_ORIGIN || "http://localhost:3000", + origin: corsOrigins.length === 1 ? corsOrigins[0] : corsOrigins, credentials: true, }) ); diff --git a/mflix/server/python-fastapi/.env.example b/mflix/server/python-fastapi/.env.example index 6dc1d0d..f0d77b2 100644 --- a/mflix/server/python-fastapi/.env.example +++ b/mflix/server/python-fastapi/.env.example @@ -1,15 +1,17 @@ # MongoDB Connection # Replace with your MongoDB Atlas connection string or local MongoDB URI -MONGO_URI="mongodb+srv://:@.mongodb.net/sample_mflix?retryWrites=true&w=majority" -MONGO_DB="sample_mflix" +MONGODB_URI=mongodb+srv://:@.mongodb.net/sample_mflix?retryWrites=true&w=majority -# Voyage AI Configuration -# API key for Voyage AI embedding model (required for Vector Search) -VOYAGE_API_KEY=your_voyage_api_key +# OPTIONAL: Voyage AI Configuration (required for Vector Search) +# Get your API key from https://www.voyageai.com/ +# VOYAGE_API_KEY=your_voyage_api_key + +# Server Configuration +PORT=3001 # CORS Configuration -# Comma-separated list of allowed origins for CORS -CORS_ORIGINS="http://localhost:3000,http://localhost:3001" +# Comma-separated list of allowed origins for cross-origin requests +CORS_ORIGINS=http://localhost:3000 # Logging Configuration # Log level: DEBUG, INFO, WARNING, ERROR, CRITICAL (default: INFO) diff --git a/mflix/server/python-fastapi/src/database/mongo_client.py b/mflix/server/python-fastapi/src/database/mongo_client.py index 37ab816..ac8e2d3 100644 --- a/mflix/server/python-fastapi/src/database/mongo_client.py +++ b/mflix/server/python-fastapi/src/database/mongo_client.py @@ -5,11 +5,13 @@ load_dotenv() -client = AsyncMongoClient(os.getenv("MONGO_URI"), +DATABASE_NAME = "sample_mflix" + +client = AsyncMongoClient(os.getenv("MONGODB_URI"), # Set application name appname="sample-app-python-mflix") -db = client[os.getenv("MONGO_DB")] +db = client[DATABASE_NAME] voyage_api_key = os.getenv("VOYAGE_API_KEY") if voyage_api_key: