Skip to content

Commit f2a8ed9

Browse files
Load env vars in app lifecycle handler on startup
1 parent b3ff7cb commit f2a8ed9

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
from typing import Optional
33
from contextlib import asynccontextmanager
4+
from dotenv import load_dotenv
45
from fastapi import FastAPI, Request, Depends, status
56
from fastapi.responses import RedirectResponse
67
from fastapi.staticfiles import StaticFiles
@@ -28,6 +29,7 @@
2829
@asynccontextmanager
2930
async def lifespan(app: FastAPI):
3031
# Optional startup logic
32+
load_dotenv()
3133
set_up_db()
3234
yield
3335
# Optional shutdown logic

0 commit comments

Comments
 (0)