2023-08-18 11:18:29 +03:00
|
|
|
import os
|
2023-08-25 13:03:13 +03:00
|
|
|
|
2023-11-14 16:31:02 +03:00
|
|
|
from packages.utils import handle_request_validation_error
|
2023-10-30 12:18:04 +03:00
|
|
|
|
2023-08-18 11:18:29 +03:00
|
|
|
if __name__ == "__main__":
|
|
|
|
# import needed here when running main.py to debug backend
|
|
|
|
# you will need to run pip install python-dotenv
|
2023-08-25 13:03:13 +03:00
|
|
|
from dotenv import load_dotenv # type: ignore
|
|
|
|
|
2023-08-18 11:18:29 +03:00
|
|
|
load_dotenv()
|
|
|
|
import pypandoc
|
2023-10-30 12:18:04 +03:00
|
|
|
from fastapi import FastAPI, HTTPException
|
2023-08-18 11:18:29 +03:00
|
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from logger import get_logger
|
|
|
|
from middlewares.cors import add_cors_middleware
|
2023-12-01 00:29:28 +03:00
|
|
|
from modules.misc.controller import misc_router
|
|
|
|
from modules.upload.controller import upload_router
|
2023-08-18 11:18:29 +03:00
|
|
|
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
app = FastAPI()
|
|
|
|
|
2023-08-25 13:03:13 +03:00
|
|
|
|
2023-08-18 11:18:29 +03:00
|
|
|
@app.on_event("startup")
|
|
|
|
async def startup_event():
|
|
|
|
if not os.path.exists(pypandoc.get_pandoc_path()):
|
|
|
|
pypandoc.download_pandoc()
|
|
|
|
|
|
|
|
|
2023-08-25 13:03:13 +03:00
|
|
|
add_cors_middleware(app)
|
2023-08-18 11:18:29 +03:00
|
|
|
|
|
|
|
|
|
|
|
app.include_router(upload_router)
|
|
|
|
app.include_router(misc_router)
|
|
|
|
|
|
|
|
|
|
|
|
@app.exception_handler(HTTPException)
|
|
|
|
async def http_exception_handler(_, exc):
|
|
|
|
return JSONResponse(
|
|
|
|
status_code=exc.status_code,
|
|
|
|
content={"detail": exc.detail},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
handle_request_validation_error(app)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
# run main.py to debug backend
|
|
|
|
import uvicorn
|
|
|
|
|
2023-08-25 13:03:13 +03:00
|
|
|
uvicorn.run(app, host="0.0.0.0", port=5050)
|