| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- # backend/app/main.py
- import sys
- import os
- # 添加当前目录到 Python 路径
- sys.path.append(os.path.dirname(os.path.abspath(__file__)))
- from fastapi import FastAPI
- from fastapi.middleware.cors import CORSMiddleware
- # 现在使用绝对导入
- from core.config import settings
- from database import engine, Base
- # 注意:暂时注释掉这些导入,我们先让基础部分运行起来
- # from api import categories, spiders, executions
- # 创建数据库表
- Base.metadata.create_all(bind=engine)
- app = FastAPI(
- title=settings.PROJECT_NAME,
- version=settings.VERSION
- )
- # CORS配置
- app.add_middleware(
- CORSMiddleware,
- allow_origins=["*"],
- allow_credentials=True,
- allow_methods=["*"],
- allow_headers=["*"],
- )
- # 暂时注释掉路由注册
- # app.include_router(categories.router)
- # app.include_router(spiders.router)
- # app.include_router(executions.router)
- @app.get("/")
- def read_root():
- return {"message": "爬虫任务调度系统 API"}
- @app.get("/health")
- def health_check():
- return {"status": "healthy", "service": "spider-scheduler"}
- if __name__ == "__main__":
- import uvicorn
- uvicorn.run(app, host="0.0.0.0", port=8000, reload=True)
|