worker_server.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. from fastapi import FastAPI
  2. from worker.api.excel_load import app as excel_load_app
  3. from worker.api.search_cli import app as search_cli_app
  4. from fastapi.middleware.cors import CORSMiddleware
  5. from config.settings import DB_URL, GOOGLE_SEARCH_DIR
  6. app = FastAPI(
  7. title="搜索微服务",
  8. description="提供关键词导入和搜索功能的统一API接口",
  9. version="1.0.0"
  10. )
  11. app.add_middleware(
  12. CORSMiddleware,
  13. allow_origins=["*"], # 允许所有域名访问
  14. allow_credentials=True,
  15. allow_methods=["*"], # 允许所有方法(GET, POST, PUT, DELETE 等)
  16. allow_headers=["*"], # 允许所有头部
  17. )
  18. # 合并两个子应用
  19. app.include_router(excel_load_app, prefix="/keywords")
  20. app.include_router(search_cli_app, prefix="/search")
  21. @app.get("/health")
  22. async def health_check():
  23. """服务健康检查"""
  24. return {"status": "healthy", 'db_url': DB_URL, 'google_search_dir':GOOGLE_SEARCH_DIR, 'msg': 'ok'}
  25. if __name__ == "__main__":
  26. import uvicorn
  27. # python .\worker\api\worker_server.py
  28. # python -m uvicorn worker:api:worker_server:app --reload
  29. uvicorn.run(app, host="127.0.0.1", port=8003)