diff --git a/app.py b/app.py index 9dce8265..4282f7eb 100644 --- a/app.py +++ b/app.py @@ -25,7 +25,7 @@ app = FastAPI( title=learnhouse_config.site_name, description=learnhouse_config.site_description, version="0.1.0", - root_path="/" + root_path="/", ) app.add_middleware( @@ -34,39 +34,36 @@ app.add_middleware( allow_origins=learnhouse_config.hosting_config.allowed_origins, allow_methods=["*"], allow_credentials=True, - allow_headers=["*"] + allow_headers=["*"], ) # Gzip Middleware (will add brotli later) app.add_middleware(GZipMiddleware, minimum_size=1000) -# Static Files -app.mount("/content", StaticFiles(directory="content"), name="content") - - # Events app.add_event_handler("startup", startup_app(app)) app.add_event_handler("shutdown", shutdown_app(app)) # JWT Exception Handler -@ app.exception_handler(AuthJWTException) +@app.exception_handler(AuthJWTException) def authjwt_exception_handler(request: Request, exc: AuthJWTException): return JSONResponse( status_code=exc.status_code, # type: ignore - content={"detail": exc.message} # type: ignore + content={"detail": exc.message}, # type: ignore ) +# Static Files +app.mount("/content", StaticFiles(directory="content"), name="content") + # Global Routes app.include_router(v1_router) # General Routes -@ app.get("/") +@app.get("/") async def root(): return {"Message": "Welcome to LearnHouse ✨"} - - diff --git a/config/config.yaml b/config/config.yaml index 0122a9db..bf151243 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -11,6 +11,9 @@ security: hosting_config: domain: learnhouse.app ssl: true + allowed_origins: + - http://localhost:3000 + - http://localhost:3001 cookies_config: domain: ".localhost" allowed_regexp: '\b((?:https?://)[^\s/$.?#].[^\s]*)\b' diff --git a/src/core/events/content.py b/src/core/events/content.py new file mode 100644 index 00000000..3098aa9d --- /dev/null +++ b/src/core/events/content.py @@ -0,0 +1,8 @@ +import os + + +async def check_content_directory(): + if not os.path.exists(f"content"): + # create folder for activity + print("Creating content directory...") + os.makedirs(f"content") diff --git a/src/core/events/events.py b/src/core/events/events.py index bc95d16e..f5a552e0 100644 --- a/src/core/events/events.py +++ b/src/core/events/events.py @@ -1,6 +1,7 @@ from typing import Callable from fastapi import FastAPI from config.config import LearnHouseConfig, get_learnhouse_config +from src.core.events.content import check_content_directory from src.core.events.database import close_database, connect_to_db from src.core.events.logs import create_logs_dir from src.core.events.sentry import init_sentry @@ -10,7 +11,7 @@ def startup_app(app: FastAPI) -> Callable: async def start_app() -> None: # Get LearnHouse Config learnhouse_config: LearnHouseConfig = get_learnhouse_config() - app.learnhouse_config = learnhouse_config # type: ignore + app.learnhouse_config = learnhouse_config # type: ignore # Init Sentry await init_sentry(app) @@ -21,10 +22,14 @@ def startup_app(app: FastAPI) -> Callable: # Create logs directory await create_logs_dir() + # Create content directory + await check_content_directory() + return start_app def shutdown_app(app: FastAPI) -> Callable: async def close_app() -> None: await close_database(app) + return close_app