Skip to content

Commit

Permalink
Use lifespan to determine mandatory variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
FledgeXu committed Aug 24, 2023
1 parent 32a0c89 commit aea8c27
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 4 additions & 3 deletions backend/api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ def determine_environment_variable(variable_name: str):
raise OSError(f"Please set the {variable_name} environment variable")


determine_environment_variable("POSTGRES_URI")
determine_environment_variable("S3_URL_WITH_CREDENTIALS")
determine_environment_variable("PRIVATE_KEY")
def determine_mandatory_environment_variables():
determine_environment_variable("POSTGRES_URI")
determine_environment_variable("S3_URL_WITH_CREDENTIALS")
determine_environment_variable("PRIVATE_KEY")


@dataclass(kw_only=True)
Expand Down
16 changes: 14 additions & 2 deletions backend/api/main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
from contextlib import asynccontextmanager
from http import HTTPStatus

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import RedirectResponse

from api import __description__, __titile__, __version__
from api.constants import constants
from api.constants import constants, determine_mandatory_environment_variables
from api.routes import files, projects, users, utils


@asynccontextmanager
async def lifespan(_: FastAPI):
determine_mandatory_environment_variables()
yield


def create_app() -> FastAPI:
app = FastAPI(title=__titile__, description=__description__, version=__version__)
app = FastAPI(
lifespan=lifespan,
title=__titile__,
description=__description__,
version=__version__,
)

@app.get("/")
async def landing() -> RedirectResponse:
Expand Down

0 comments on commit aea8c27

Please sign in to comment.