-
Notifications
You must be signed in to change notification settings - Fork 4
updated app logic #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,11 +1,30 @@ | ||||||||||||||||
| import uvicorn | ||||||||||||||||
| from app.main import app | ||||||||||||||||
| import os | ||||||||||||||||
| import sys | ||||||||||||||||
| from pathlib import Path | ||||||||||||||||
|
|
||||||||||||||||
| def main(): | ||||||||||||||||
| # Set project root as working directory | ||||||||||||||||
| current_dir = Path(__file__).resolve().parent | ||||||||||||||||
arvi18 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| sys.path.append(str(current_dir)) | ||||||||||||||||
arvi18 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
|
|
||||||||||||||||
| # Read environment-based settings | ||||||||||||||||
| env = os.getenv("ENV", "development").lower() | ||||||||||||||||
arvi18 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| port = int(os.getenv("PORT", 8000)) | ||||||||||||||||
|
Comment on lines
+12
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing Error HandlingConverting port to int without error handling can crash the application if PORT environment variable contains non-numeric value. This creates a reliability issue during deployment with misconfigured environment.
Suggested change
Standards
|
||||||||||||||||
| reload = env == "development" | ||||||||||||||||
arvi18 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| workers = int(os.getenv("UVICORN_WORKERS", 1 if reload else 4)) | ||||||||||||||||
arvi18 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
|
|
||||||||||||||||
| if __name__ == "__main__": | ||||||||||||||||
| uvicorn.run( | ||||||||||||||||
| "app.main:app", | ||||||||||||||||
| host="0.0.0.0", | ||||||||||||||||
| port=8000, | ||||||||||||||||
| reload=True, | ||||||||||||||||
| log_level="info" | ||||||||||||||||
| ) | ||||||||||||||||
| port=port, | ||||||||||||||||
| reload=reload, | ||||||||||||||||
| workers=workers, | ||||||||||||||||
| log_level="debug" if reload else "info", | ||||||||||||||||
arvi18 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| proxy_headers=True, # Trust X-Forwarded-For if behind proxy | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security Consideration: Setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. legit reply from a legit author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. legit reply from a legit reviewer |
||||||||||||||||
| forwarded_allow_ips="*", # Allow all forwarded IPs | ||||||||||||||||
arvi18 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| timeout_keep_alive=30 # Optional tuning | ||||||||||||||||
| ) | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrestricted Forwarded IPsSetting forwarded_allow_ips to '*' trusts all IP addresses in X-Forwarded-For headers. This enables IP spoofing attacks where malicious clients can forge their source IP address.
Suggested change
Standards
|
||||||||||||||||
|
|
||||||||||||||||
| if __name__ == "__main__": | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. legit review comment from a legit reviewer |
||||||||||||||||
| main() | ||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing Docstring
The main function lacks a docstring explaining its purpose and behavior. This reduces code maintainability as future developers won't understand the function's role without reading its implementation.
Standards