diff --git a/src/server/app.py b/src/server/app.py index d8f2e67..d796223 100644 --- a/src/server/app.py +++ b/src/server/app.py @@ -1,6 +1,7 @@ from flask import Flask, jsonify, request, send_from_directory from flask_cors import CORS import os +import sys app = Flask(__name__) CORS(app) # Enable CORS for all routes @@ -11,6 +12,33 @@ from parse_archive import ArchiveParser # Initialize the archive parser archive_parser = ArchiveParser() +# Validate archive directory at startup +def validate_archive_directory(): + """Validate that the archive directory exists and has content""" + archive_dir = os.environ.get('ARCHIVE_DIR', '/app/archive') + print(f"Checking archive directory: {archive_dir}") + + if not os.path.exists(archive_dir): + print(f"ERROR: Archive directory does not exist: {archive_dir}") + return False + + try: + # Try to list directories in archive + dirs = os.listdir(archive_dir) + if not dirs: + print(f"WARNING: Archive directory is empty: {archive_dir}") + else: + print(f"INFO: Archive directory contains {len(dirs)} items") + return True + except Exception as e: + print(f"ERROR: Cannot access archive directory {archive_dir}: {e}") + return False + +# Validate at startup +if not validate_archive_directory(): + print("FATAL: Archive directory validation failed. Application cannot start.") + sys.exit(1) + # Serve static files from the website directory # The website directory is at the same level as the src directory