| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- # backend/app/main.py
- 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=settings.CORS_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)
|