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