mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: add content folder
This commit is contained in:
parent
6d97aa2072
commit
80fbb0ba2f
4 changed files with 25 additions and 12 deletions
15
app.py
15
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,17 +34,13 @@ 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))
|
||||
|
|
@ -55,10 +51,13 @@ app.add_event_handler("shutdown", shutdown_app(app))
|
|||
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)
|
||||
|
||||
|
|
@ -68,5 +67,3 @@ app.include_router(v1_router)
|
|||
@app.get("/")
|
||||
async def root():
|
||||
return {"Message": "Welcome to LearnHouse ✨"}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
8
src/core/events/content.py
Normal file
8
src/core/events/content.py
Normal 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")
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue