From 10ff66b6bfdf33b3fba97800433a6692dcacce29 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 14 Jan 2021 19:06:23 -0800 Subject: fastapi: /favicon.ico handler HTML responses in the browser should use the indicated path (/static/ia-favicon.ico), but some other responses fall through (like API docs, I think? or unhandled exceptions), so giving up and just handling this route. haproxy should cache if it gets lots of hits. --- fatcat_scholar/web.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fatcat_scholar/web.py b/fatcat_scholar/web.py index 05bced1..b1107c6 100644 --- a/fatcat_scholar/web.py +++ b/fatcat_scholar/web.py @@ -10,7 +10,7 @@ from typing import Optional, Any import babel.support from fastapi import FastAPI, APIRouter, Request, Depends, Response from fastapi.staticfiles import StaticFiles -from fastapi.responses import PlainTextResponse, JSONResponse +from fastapi.responses import PlainTextResponse, JSONResponse, FileResponse import sentry_sdk from sentry_sdk.integrations.asgi import SentryAsgiMiddleware from starlette_prometheus import metrics, PrometheusMiddleware @@ -242,6 +242,10 @@ app.include_router(api) app.mount("/static", StaticFiles(directory="fatcat_scholar/static"), name="static") +@app.get("/favicon.ico", include_in_schema=False) +async def favicon(): + return FileResponse("fatcat_scholar/static/ia-favicon.ico", media_type="image/x-icon") + ROBOTS_ALLOW = open("fatcat_scholar/static/robots.allow.txt", "r").read() ROBOTS_DISALLOW = open("fatcat_scholar/static/robots.disallow.txt", "r").read() -- cgit v1.2.3