Loads of boiler plating
Some checks failed
Build, Push, and Deploy to Nomad / docker-nomad (push) Failing after 4m31s

This commit is contained in:
Henrik Jess
2024-12-10 16:40:17 +01:00
parent 6b96d9f6de
commit 454de7aae5
9 changed files with 221 additions and 73 deletions

40
app.py
View File

@@ -1,16 +1,36 @@
import uvicorn
from fastapi import FastAPI
from dotenv import load_dotenv
from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
import json
import os
load_dotenv()
app = FastAPI()
app = FastAPI(title=os.getenv("APP_NAME", "Default App"))
# Mount static files
app.mount("/static", StaticFiles(directory="static"), name="static")
@app.get("/")
def read_root():
return {"debug": os.getenv("DEBUG", "false")}
# Templates directory
templates = Jinja2Templates(directory="templates")
# Load JSON data
with open("mock_data.json") as file:
data = json.load(file)
if __name__ == "__main__":
uvicorn.run("app:app", host="0.0.0.0", port=9210, reload=True)
# Index route
@app.get("/", response_class=HTMLResponse)
async def get_index(request: Request):
return templates.TemplateResponse("index.html", {"request": request, "data": data})
# Category route
@app.get("/category/{category_name}", response_class=HTMLResponse)
async def get_category(request: Request, category_name: str):
category_file = f"data/{category_name}/index.html"
if os.path.exists(category_file):
with open(category_file) as file:
category_content = file.read()
return templates.TemplateResponse(
"category.html",
{"request": request, "category_name": category_name, "content": category_content}
)
return HTMLResponse("Kategori ikke fundet", status_code=404)