move main function, launch module directly

This commit is contained in:
Jörn-Michael Miehe 2022-09-17 19:13:59 +00:00
parent bcc833d3a6
commit fbf6c550d2
4 changed files with 25 additions and 21 deletions

View file

@ -8,7 +8,7 @@
"name": "Main Module",
"type": "python",
"request": "launch",
"module": "ovdashboard_api.main",
"module": "ovdashboard_api",
"justMyCode": true
}
]

View file

@ -9,8 +9,11 @@ from logging.config import dictConfig
from pydantic import BaseModel
from .app import app
from .settings import SETTINGS
__all__ = ["app"]
class LogConfig(BaseModel):
"""

View file

@ -0,0 +1,21 @@
from uvicorn import run as uvicorn_run
from .dav_common import webdav_check
def main() -> None:
"""
If the `main` script is run, `uvicorn` is used to run the app.
"""
if webdav_check():
uvicorn_run(
app="ovdashboard_api:app",
host="0.0.0.0",
port=8000,
reload=True,
)
if __name__ == "__main__":
main()

View file

@ -9,9 +9,7 @@ Creates the main `FastAPI` app.
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from uvicorn import run as uvicorn_run
from .dav_common import webdav_check
from .routers import main_router
from .settings import SETTINGS
@ -56,21 +54,3 @@ else:
allow_headers=["*"],
expose_headers=["*"],
)
def main() -> None:
"""
If the `main` script is run, `uvicorn` is used to run the app.
"""
if webdav_check():
uvicorn_run(
app="ovdashboard_api.main:app",
host="0.0.0.0",
port=8000,
reload=True,
)
if __name__ == "__main__":
main()