feat: add content folder

This commit is contained in:
swve 2023-07-11 14:49:32 +01:00
parent 6d97aa2072
commit 80fbb0ba2f
4 changed files with 25 additions and 12 deletions

19
app.py
View file

@ -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 ✨"}

View file

@ -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'

View file

@ -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")

View file

@ -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
@ -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