diff options
author | Bryan Newbold <bnewbold@archive.org> | 2021-01-14 19:06:23 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@archive.org> | 2021-01-14 19:23:47 -0800 |
commit | 10ff66b6bfdf33b3fba97800433a6692dcacce29 (patch) | |
tree | 71a551cd3116153ab90721292e8f2b8c46a6bbe1 | |
parent | 866077830070739191e7e21bc471870efd8bb9bf (diff) | |
download | fatcat-scholar-10ff66b6bfdf33b3fba97800433a6692dcacce29.tar.gz fatcat-scholar-10ff66b6bfdf33b3fba97800433a6692dcacce29.zip |
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.
-rw-r--r-- | fatcat_scholar/web.py | 6 |
1 files changed, 5 insertions, 1 deletions
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() |