Skip to content

Commit

Permalink
issue #172: home redirect to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
k-allagbe committed Nov 5, 2024
1 parent f69027a commit 736c3d9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
17 changes: 14 additions & 3 deletions app/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from contextlib import asynccontextmanager

from dotenv import load_dotenv
from fastapi import FastAPI
from pipeline import GPT, OCR
Expand All @@ -11,7 +13,7 @@
class Settings(BaseSettings):
api_endpoint: str = Field(alias="azure_api_endpoint")
api_key: str = Field(alias="azure_api_key")
base_path: str = ""
base_path: str = Field(alias="api_base_path")
fertiscan_db_url: PostgresDsn
fertiscan_schema: str
fertiscan_storage_url: str
Expand All @@ -20,13 +22,22 @@ class Settings(BaseSettings):
openai_api_endpoint: str = Field(alias="azure_openai_endpoint")
openai_api_key: str = Field(alias="azure_openai_key")
otel_exporter_otlp_endpoint: str | None = None
swagger_base_path: str = ""
swagger_path: str = "/docs"
upload_folder: str = "uploads"
testing: str = "false"


def configure(app: FastAPI, settings: Settings):
@asynccontextmanager
async def lifespan(app: FastAPI):
app.pool.open()
yield
app.pool.close()


def create_app(settings: Settings):
app = FastAPI(
lifespan=lifespan, docs_url=settings.swagger_path, root_path=settings.base_path
)
pool = ConnectionPool(
open=False,
conninfo=settings.fertiscan_db_url.unicode_string(),
Expand Down
23 changes: 9 additions & 14 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from http import HTTPStatus
from typing import Annotated

from fastapi import Depends, FastAPI, Form, HTTPException, Request, UploadFile
from fastapi.concurrency import asynccontextmanager
from fastapi.responses import JSONResponse
from fastapi import Depends, Form, HTTPException, Request, UploadFile
from fastapi.responses import JSONResponse, RedirectResponse
from pipeline import GPT, OCR
from psycopg_pool import ConnectionPool
from pydantic import UUID4

from app.config import Settings, configure
from app.config import Settings, create_app
from app.controllers.data_extraction import extract_data
from app.controllers.inspections import (
create_inspection,
Expand All @@ -32,16 +31,7 @@
from app.models.users import User
from app.sanitization import custom_secure_filename


@asynccontextmanager
async def lifespan(app: FastAPI):
app = configure(app, get_settings())
app.pool.open()
yield
app.pool.close()


app = FastAPI(lifespan=lifespan)
app = create_app(get_settings())


@app.exception_handler(Exception)
Expand All @@ -50,6 +40,11 @@ async def global_exception_handler(_: Request, e: Exception):
return JSONResponse(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, content=str(e))


@app.get("/", tags=["Home"])
async def home():
return RedirectResponse(url=app.docs_url)


@app.get("/health", tags=["Monitoring"], response_model=HealthStatus)
async def health_check():
return HealthStatus()
Expand Down

0 comments on commit 736c3d9

Please sign in to comment.