75 lines
2.0 KiB
Python
75 lines
2.0 KiB
Python
# uvicorn main:app --host=127.0.0.1 --port=8030 --reload
|
|
from config.config import settings
|
|
from fastapi import Depends, FastAPI, BackgroundTasks, Request
|
|
from dependencies import get_token_header
|
|
from interface import route as interface_route
|
|
from scripts.common.mongodb import get_mongo
|
|
from typing import Optional
|
|
from scripts.logger import logger
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
# from apscheduler.events import EVENT_JOB_EXECUTED
|
|
# from jobs.jobs import Schedule, job_execute
|
|
tags_metadata = [
|
|
# {
|
|
# "name": "common",
|
|
# "description": "Operations with users. The **login** logic is also here.",
|
|
# },
|
|
{
|
|
"name": "common",
|
|
"description": "Manage items. So _fancy_ they have their own docs.",
|
|
"externalDocs": {
|
|
"description": "Items external docs",
|
|
"url": "https://fastapi.tiangolo.com/",
|
|
},
|
|
},
|
|
]
|
|
|
|
|
|
def create_app():
|
|
application = FastAPI(dependencies=[Depends(get_token_header)],
|
|
openapi_tags=tags_metadata)
|
|
application.include_router(interface_route.router, prefix="/interface")
|
|
return application
|
|
|
|
|
|
app = create_app()
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.origins,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
@app.on_event("startup")
|
|
async def startup_event():
|
|
app.state.mongo = await get_mongo()
|
|
# Schedule.start()
|
|
# Schedule.add_listener(job_execute, EVENT_JOB_EXECUTED)
|
|
|
|
|
|
@app.on_event("shutdown")
|
|
async def shutdown_event():
|
|
app.state.mongo.close()
|
|
await app.state.mongo.wait_close()
|
|
|
|
|
|
@app.get("/")
|
|
async def root(request: Request):
|
|
# db = request.app.state.mongo
|
|
# keys = await db.get("online_devices")
|
|
logger.info("starting!")
|
|
|
|
return {"message": "kajsk"}
|
|
|
|
|
|
if __name__ == '__main__':
|
|
import uvicorn
|
|
uvicorn.run(app='main:app',
|
|
host="0.0.0.0",
|
|
port=8030,
|
|
reload=True,
|
|
debug=True)
|