Skip to content

Commit

Permalink
Update user endpoint import in API router and adjust port number for …
Browse files Browse the repository at this point in the history
…uvicorn run in main.py. Update cffi package to version 1.16.0.
  • Loading branch information
Arteiii committed Feb 17, 2024
1 parent 0211ce9 commit 842330d
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 20 deletions.
4 changes: 2 additions & 2 deletions authly/api/api_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from authly.core.config import application_config

# routes:
from user.endpoint import user as user_route
from authly.api.user.endpoint import user as user_router

API_CONFIG = application_config.API # type: ignore

Expand Down Expand Up @@ -40,7 +40,7 @@ def check_api_paths(f, s) -> bool:
f" \\__ https://example.com{API_ROUTE}/",
)

api_main_router.include_router(user_route, prefix="/user")
api_main_router.include_router(user_router, prefix="/user")


@api_main_router.get("/")
Expand Down
24 changes: 9 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import uvicorn
import hypercorn
import sys
from authly import app


def run_development():
Expand All @@ -13,7 +12,7 @@ def run_development():
# port=8000: The port number on which the server will listen for incoming connections
# reload=True: Enables automatic code reloading when changes are detected during development
uvicorn.run(
"authly.app:app", host="127.0.0.1", port=8000, log_level="debug", reload=True
"authly.app:app", host="127.0.0.1", port=8080, log_level="debug", reload=True
)

# log_level="debug": The log level for uvicorn. Controls the verbosity of log messages
Expand All @@ -26,37 +25,32 @@ def run_development():


def run_production():
# Production configuration using Hypercorn
config = hypercorn.Config.from_mapping(
bind="0.0.0.0:8000", # Specify the host and port
loglevel="error", # Log level (error for production)
workers=2, # Number of worker processes (adjust as needed)
# Additional Hypercorn configuration options can be added here
# Production configuration using uvicorn
uvicorn.run(
"authly.app:app", host="0.0.0.0", port=80, log_level="info", reload=False

Check warning on line 30 in main.py

View check run for this annotation

codefactor.io / CodeFactor

main.py#L30

Possible binding to all interfaces. (B104)
)

hypercorn.run(app.app, config=config)


def run_custom(**kwargs):
# Custom configuration using provided keyword arguments
uvicorn.run("authly.app:app", **kwargs)


def main():
if len(sys.argv) < 2 or sys.argv[1] not in ["development", "production", "custom"]:
if len(sys.argv) < 2 or sys.argv[1] not in ["dev", "production", "custom"]:
print("Usage:")
print("Development: python main.py development")
print("Production: python main.py production")
print("Development: python main.py dev")
print("Production: python main.py deploy")
print(
"Custom: python main.py custom --host=127.0.0.1 --port=8000 --log-level=debug --reload"
)
sys.exit(1)

mode = sys.argv[1]

if mode == "development":
if mode == "dev":
run_development()
elif mode == "production":
elif mode == "deploy":
run_production()
elif mode == "custom":
# Extract command-line arguments for custom mode (skipping the script name and mode)
Expand Down
156 changes: 155 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "README.md"
python = "^3.12"
fastapi = "^0.109.2"
uvicorn = {extras = ["standard"], version = "^0.27.1"}
hypercorn = "^0.16.0"
hypercorn = {extras = ["trio"], version = "^0.16.0"}


[build-system]
Expand Down
Loading

0 comments on commit 842330d

Please sign in to comment.