From 514b0338844334aa4aaf332c6e29efb6a1aadaa6 Mon Sep 17 00:00:00 2001 From: B Wu Date: Wed, 7 Aug 2024 20:11:52 -0700 Subject: feat: add static and template rendering --- kennel/main.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'kennel/main.py') diff --git a/kennel/main.py b/kennel/main.py index f0eaaca..3cca2c0 100644 --- a/kennel/main.py +++ b/kennel/main.py @@ -2,6 +2,8 @@ import uuid import structlog from fastapi import FastAPI, Request, Response +from fastapi.staticfiles import StaticFiles +from fastapi.templating import Jinja2Templates app = FastAPI() logger = structlog.get_logger() @@ -33,6 +35,8 @@ async def logger_middleware(request: Request, call_next): return response +templates = Jinja2Templates(directory="templates") + @app.get("/healthcheck") async def healthcheck(): @@ -40,6 +44,10 @@ async def healthcheck(): @app.get("/") -async def read_main(): - logger.info("In root path") - return {"msg": "Hello World"} +async def read_main(request: Request): + return templates.TemplateResponse( + request=request, name="index.html" + ) + +app.mount("/static", StaticFiles(directory = "static"), name = "static") + -- cgit v1.3