Browse Source

set root_path by command line

chenhaiyang 1 year ago
parent
commit
ab4c636086
3 changed files with 9 additions and 4 deletions
  1. 1 1
      Dockerfile
  2. 7 2
      app/api/routers/algorithms.py
  3. 1 1
      app/main.py

+ 1 - 1
Dockerfile

@@ -15,4 +15,4 @@ ENV TZ=Asia/Shanghai
 
 EXPOSE 8002
 
-CMD ["uvicorn", "app.main:app", "--log-level", "info", "--host", "0.0.0.0", "--port", "8002"]
+CMD ["uvicorn", "app.main:app", "--root-path /env-py", "--log-level", "info", "--host", "0.0.0.0", "--port", "8002"]

+ 7 - 2
app/api/routers/algorithms.py

@@ -1,15 +1,15 @@
-from fastapi import APIRouter
+from fastapi import APIRouter, Request
 from loguru import logger
 
 from app.controllers.algorithms.graph_coloring import get_graph_coloring
 from app.controllers.algorithms.meeting_attendee_recommendation import (
     build_recommendations,
 )
-from app.models.domain.algorithms import GraphColoringRequest, GraphColoringResponse
 from app.models.domain.algorithms import (
     AttendeesRecommendationRequest,
     AttendeesRecommendationResponse,
 )
+from app.models.domain.algorithms import GraphColoringRequest, GraphColoringResponse
 
 router = APIRouter()
 
@@ -19,6 +19,11 @@ async def get_living_condition():
     return {"message": "alive"}
 
 
+@router.get("/app")
+def read_main(request: Request):
+    return {"message": "Hello World", "root_path": request.scope.get("root_path")}
+
+
 @router.post("/graph-coloring", response_model=GraphColoringResponse)
 async def get_graph_coloring_result(graph: GraphColoringRequest):
     is_solvable, colored = await get_graph_coloring(graph.graph)

+ 1 - 1
app/main.py

@@ -27,7 +27,7 @@ logging.getLogger().handlers = [InterceptHandler()]
 
 
 def get_application() -> FastAPI:
-    application = FastAPI(title=settings.PROJECT_NAME, root_path="/env-py")
+    application = FastAPI(title=settings.PROJECT_NAME)
 
     application.add_event_handler("startup", create_start_app_handler())