Refactoring, added docstrings
This commit is contained in:
@@ -6,6 +6,12 @@ from .routes import router
|
||||
|
||||
|
||||
def get_app(port: int, name: str) -> FastAPI:
|
||||
"""
|
||||
Creates FastAPI object and runs integrate_onion
|
||||
:param port: Must be same with port on which uvicorn is running
|
||||
:param name: Name of service
|
||||
:return: FastAPI object with onion.cleanup function on shutdown
|
||||
"""
|
||||
onion = integrate_onion(port, name)
|
||||
return FastAPI(
|
||||
title=f'dragonion-server: {name}',
|
||||
@@ -15,6 +21,12 @@ def get_app(port: int, name: str) -> FastAPI:
|
||||
|
||||
|
||||
def run(name: str, port: int | None = get_available_port()):
|
||||
"""
|
||||
Runs service with specified name and starts onion
|
||||
:param name: Name of service
|
||||
:param port: Port where to start service, if not specified - gets random available
|
||||
:return:
|
||||
"""
|
||||
if port is None:
|
||||
port = get_available_port()
|
||||
app = get_app(port, name)
|
||||
|
||||
Reference in New Issue
Block a user