main.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # backend/app/main.py
  2. import sys
  3. import os
  4. # 添加当前目录到 Python 路径
  5. sys.path.append(os.path.dirname(os.path.abspath(__file__)))
  6. from fastapi import FastAPI
  7. from fastapi.middleware.cors import CORSMiddleware
  8. # 现在使用绝对导入
  9. from core.config import settings
  10. from database import engine, Base
  11. # 注意:暂时注释掉这些导入,我们先让基础部分运行起来
  12. # from api import categories, spiders, executions
  13. # 创建数据库表
  14. Base.metadata.create_all(bind=engine)
  15. app = FastAPI(
  16. title=settings.PROJECT_NAME,
  17. version=settings.VERSION
  18. )
  19. # CORS配置
  20. app.add_middleware(
  21. CORSMiddleware,
  22. allow_origins=["*"],
  23. allow_credentials=True,
  24. allow_methods=["*"],
  25. allow_headers=["*"],
  26. )
  27. # 暂时注释掉路由注册
  28. # app.include_router(categories.router)
  29. # app.include_router(spiders.router)
  30. # app.include_router(executions.router)
  31. @app.get("/")
  32. def read_root():
  33. return {"message": "爬虫任务调度系统 API"}
  34. @app.get("/health")
  35. def health_check():
  36. return {"status": "healthy", "service": "spider-scheduler"}
  37. if __name__ == "__main__":
  38. import uvicorn
  39. uvicorn.run(app, host="0.0.0.0", port=8000, reload=True)