Skip to content

Commit

Permalink
Launch uvicorn from python
Browse files Browse the repository at this point in the history
  • Loading branch information
ankith26 committed Dec 20, 2024
1 parent f783636 commit 8305daf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ COPY --from=python_cache /venv /venv
COPY --from=node_builder /frontend/dist /app/frontend/dist
COPY backend backend
WORKDIR /app/backend
CMD uvicorn main:app --host "$HOST_PRIVATE" --port "$HOST_PORT"
CMD ["python3", "main.py"]
13 changes: 12 additions & 1 deletion backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from fastapi import FastAPI, Request
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
import uvicorn

from config import HOST_SUBPATH
from config import HOST_PORT, HOST_PRIVATE, HOST_SUBPATH
from routes.auth import router as auth_router
from routes.courses import router as course_router
from routes.members import router as members_router
Expand Down Expand Up @@ -59,3 +60,13 @@ async def diagnostics(request: Request):

# serve frontend
app.mount("/", StaticFiles(directory=FRONTEND_PATH, html=True), "frontend")

if __name__ == "__main__":
# forwarded_allow_ips set to * so that the nginx headers are trusted
uvicorn.run(
"main:app",
host=HOST_PRIVATE,
port=HOST_PORT,
proxy_headers=True,
forwarded_allow_ips="*",
)

0 comments on commit 8305daf

Please sign in to comment.