Run the FastAPI server.
(host: str = "127.0.0.1", port: int = 8000, reload: bool = False)
| 772 | |
| 773 | |
| 774 | def run_server(host: str = "127.0.0.1", port: int = 8000, reload: bool = False): |
| 775 | """Run the FastAPI server.""" |
| 776 | # Ensure static directory exists |
| 777 | create_static_directory() |
| 778 | |
| 779 | # Debug: Check database connectivity |
| 780 | try: |
| 781 | stats = db.get_stats() |
| 782 | print(f"✅ Database connected: {stats['total']} workflows found") |
| 783 | if stats["total"] == 0: |
| 784 | print("🔄 Database is empty. Indexing workflows...") |
| 785 | db.index_all_workflows() |
| 786 | stats = db.get_stats() |
| 787 | except Exception as e: |
| 788 | print(f"❌ Database error: {e}") |
| 789 | print("🔄 Attempting to create and index database...") |
| 790 | try: |
| 791 | db.index_all_workflows() |
| 792 | stats = db.get_stats() |
| 793 | print(f"✅ Database created: {stats['total']} workflows indexed") |
| 794 | except Exception as e2: |
| 795 | print(f"❌ Failed to create database: {e2}") |
| 796 | stats = {"total": 0} |
| 797 | |
| 798 | # Debug: Check static files |
| 799 | static_path = Path("static") |
| 800 | if static_path.exists(): |
| 801 | files = list(static_path.glob("*")) |
| 802 | print(f"✅ Static files found: {[f.name for f in files]}") |
| 803 | else: |
| 804 | print(f"❌ Static directory not found at: {static_path.absolute()}") |
| 805 | |
| 806 | print("🚀 Starting N8N Workflow Documentation API") |
| 807 | print(f"📊 Database contains {stats['total']} workflows") |
| 808 | print(f"🌐 Server will be available at: http://{host}:{port}") |
| 809 | print(f"📁 Static files at: http://{host}:{port}/static/") |
| 810 | |
| 811 | uvicorn.run( |
| 812 | "api_server:app", |
| 813 | host=host, |
| 814 | port=port, |
| 815 | reload=reload, |
| 816 | access_log=True, # Enable access logs for debugging |
| 817 | log_level="info", |
| 818 | ) |
| 819 | |
| 820 | |
| 821 | if __name__ == "__main__": |
no test coverage detected