Skip to content

Commit

Permalink
[ENH] Changed the favicon to neurobagel logo (#222)
Browse files Browse the repository at this point in the history
* Changed the favicon to neurobagel logo

* Added docstrings

* Changed the titles

* Updated favicon_url
  • Loading branch information
rmanaem authored Nov 15, 2023
1 parent 9112bb9 commit 3c44558
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import ORJSONResponse
from fastapi.openapi.docs import get_redoc_html, get_swagger_ui_html
from fastapi.responses import ORJSONResponse, RedirectResponse

from .api import utility as util
from .api.routers import attributes, query

app = FastAPI(default_response_class=ORJSONResponse)
app = FastAPI(
default_response_class=ORJSONResponse, docs_url=None, redoc_url=None
)
favicon_url = "https://raw.githubusercontent.com/neurobagel/documentation/main/docs/imgs/logo/neurobagel_favicon.png"

app.add_middleware(
CORSMiddleware,
Expand All @@ -24,6 +28,38 @@
)


@app.get("/favicon.ico", include_in_schema=False)
async def favicon():
"""
Overrides the default favicon with a custom one.
"""
return RedirectResponse(url=favicon_url)


@app.get("/docs", include_in_schema=False)
def overridden_swagger():
"""
Overrides the Swagger UI HTML for the "/docs" endpoint.
"""
return get_swagger_ui_html(
openapi_url="/openapi.json",
title="Neurobagel API",
swagger_favicon_url=favicon_url,
)


@app.get("/redoc", include_in_schema=False)
def overridden_redoc():
"""
Overrides the Redoc HTML for the "/redoc" endpoint.
"""
return get_redoc_html(
openapi_url="/openapi.json",
title="Neurobagel API",
redoc_favicon_url=favicon_url,
)


@app.on_event("startup")
async def auth_check():
"""Checks whether username and password environment variables are set."""
Expand Down

0 comments on commit 3c44558

Please sign in to comment.